1
遠程SSH命令我不能運行使用期望script.It只是登錄到遠程主機和exits.Here是代碼無法運行與預期的腳本
#!/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
}
}
只得到遠程主機上的命令進入遠程主機並退出。 [深@主機1:〜] $ ./sshexpect USER1主機2 連接到存儲
spawn ssh [email protected]
Password:
host2$
[[email protected]:~]$
是語法錯了嗎? 我是tcl腳本新手。
我理解錯誤,但我沒有得到什麼呢下面的線代表 -re {\ $ $} 而且也是爲什麼我們需要在腳本末尾輸入 預計爲 – anudeep
'-re'選項使用正則表達式模式而不是默認的glob模式。我指定提示符是行尾*處的美元符號和空格*。如果期望看到一個美元符號和一個空格,然後是其他文本,則不會將其作爲提示進行匹配。 '期望eof'基本上意味着「等到產生的過程被關閉」 - 這裏不是必須的,但通常是很好的做法。 –
我試過仍然不適合我。它顯示「登錄失敗」並退出。 它只是登錄到遠程框中,然後空白,並在「登錄失敗」後退出 – anudeep