我的要求是从本地计算机挂载远程服务器上的所有目录。挂载只能在我以su用户身份登录后才能发生。
以下是我的剧本:
#! /bin/bash
set timeout 20
ip="xx.xx.xxx.xxx"
server_username="root"
server_password="yuyuyuyuyuy"
echo "going to mount the directory with root permission"
CMD1="\$@mount -a "
VAR2=$(expect -c "
spawn ssh -o StrictHostKeyChecking=no $server_username@$ip $CMD1
match_max 100000
expect \"*?assword:*\"
send -- \"$server_password\r\"
send -- "su"
send -- \"$server_password\r\"
send -- \"\r\"
expect eof
")
echo "===============Done configuration of Server $ip"
但是这个脚本似乎没有做任何事情。它没有任何状态任何错误。能帮我做这个工作吗?
谢谢!
答案 0 :(得分:0)
将脚本修改为:
expect {
-re "\"*?assword:*\"" {send -- \"$server_password\r\" }
timeout {}
}
不期望发送通常不起作用。