【发布时间】:2014-03-06 00:40:01
【问题描述】:
我正在尝试创建一个脚本,该脚本将登录到服务器,运行一些命令,同时向用户提供信息。 我可以使用脚本很好地登录服务器,我的问题是我得到的输出。我的脚本是这样的:
#!/bin/bash
/usr/bin/expect << SSHLOGIN
set timeout 600
spawn ssh user@myServer.com
expect {
"Are you sure you want to continue connecting (yes/no)?" {
send "yes\n";exp_continue
}
Password: {
send "$2\n"
}
}
expect {
"# " {
send "echo \"Current Directory is:\" \n"
}
}
expect "# " {
send "pwd \n"
}
expect {
"# " {
send "exit \n"
}
}
wait
SSHLOGIN
&我的输出如下:
spawn ssh user@myServer.com
Password:
You have new mail.
DISPLAY set to user.myServer:0.0
# echo "Current Directory is:"
Current Directory is:
# pwd
/home/user/
我想要达到的输出是这样的:
spawn ssh user@myServer.com
Password:
You have new mail.
DISPLAY set to user.myServer:0.0
Current Directory is:
/home/user/
我尝试过使用 log_user 0/1、stty 等。但我似乎无法正确使用这些...
任何帮助将不胜感激。
【问题讨论】: