【发布时间】:2016-03-28 21:42:39
【问题描述】:
我无法使用期望脚本在远程主机上运行命令。它只是登录到远程主机并退出。这是代码
#!/usr/bin/expect
set timeout 15
puts "connecting to the storage\n"
set user [lindex $argv 0]
set host [lindex $argv 1]
set pass "root123"
spawn ssh "$user\@$host"
expect {
"Password: " {
send "$pass\r"
sleep 1
expect {
"$ " {
send "isi quota quotas list|grep ramesh\r" }
"$ " {
send "exit\r" }
}
}
"(yes/no)? " {
send "yes\r"
expect {
"$ " { send "ls\r" }
"$ " { send "exit\r" }
"> " {}
}
}
default {
send_user "login failed\n"
exit 1
}
}
它只进入远程主机并退出。 [deep@host1:~]$ ./sshexpect user1 host2 连接到存储
spawn ssh user1@host2
Password:
host2$
[deep@host1:~]$
语法错了吗? 我是 tcl 脚本的新手。
【问题讨论】: