0
SCRIPT:Expect腳本運行只需要一個命令,並顯示錯誤
#!/usr/bin/expect
set username "sv111111"
set password "Sandy789"
set f [open "servers.txt"]
set hosts [split [read $f] "\n"]
close $f
foreach host $hosts {
#spawn ssh -o StrictHostKeyChecking=no [email protected]$hosts
spawn ssh [email protected]$host
expect "[email protected]$host's password:"
send -- "$password\n"
expect "$"
send -- "sudo -u sandy /opt/sandy/ship/common/tools/arpq.sh\n"
expect "[email protected]$host's password:"
send -- "$password\n"
expect "$"
send -- "sudo -u sandy /opt/sandy/ship/common/tools/showps2.pl\n"
expect "$"
send -- "exit\n"
expect eof
close
}
在上述腳本
它完美地運行在servers.txt文件中提到的所有服務器的第一須藤命令。第二個sudo命令沒有執行,並顯示下面的錯誤。
spawn ssh [email protected]
ssh: : Name or service not known
send: spawn id exp10 not open
while executing
"send -- "$password\n""
("foreach" body line 5)
invoked from within
"foreach host $hosts {
#spawn ssh -o StrictHostKeyChecking=no [email protected]$hosts
spawn ssh [email protected]$host
expect "[email protected]$host's password:"
send -- ..."
(file "./sandy_try.sh" line 8)
請幫助
喜@Glenn傑克曼:我需要使用郵件服務器的日誌文件發送到兩個用戶。你能幫忙嗎? – sandeep
提問題 –
我不知道glenn。我不能再問新問題 – sandeep