2014-12-20 89 views
1

你能告訴我爲什麼這個Expect腳本在循環模式下顯示日曆嗎? 我只想看到一個日曆。使用expect登錄併發出命令

#!/usr/bin/expect 
set fid [open /Users/john/secret] 
set password [read $fid] 
close $fid 

spawn ssh [lindex $argv 0]@[lindex $argv 1] 
expect { 
-re ".*Are.*.*yes.*no.*" { 
send "yes\n" 
exp_continue 
} 

"*?assword:*" { 
send $password 
send "\n" 
exp_continue 
} 

"*$*" { 
send "cal\r" 
exp_continue 
} 

"*$*" { 
send "exit\r" 
} 

回答

2

這似乎是我錯了

"*$*" { 
send "cal\r" 
exp_continue 
} 

"*$*" { 
send "exit\r" 
} 

一個美元符號的檢查是在同一水平等你以後發送cal\r你循環,它會尋找$再次和問題cal\r再未達到最後的"*$*" {

你可能一直在爲此?

#!/usr/bin/expect 
set fid [open /Users/john/secret] 
set password [read $fid] 
close $fid 

spawn ssh [lindex $argv 0]@[lindex $argv 1] 
expect { 
    -re ".*Are.*.*yes.*no.*" { 
     send "yes\n" 
     exp_continue 
    } 
    "*?assword:*" { 
     send $password 
     send "\n" 
     exp_continue 
    } 
    "*$*" { 
     send "cal\r" 
     expect "*$*" { 
      send "exit\r" 
     } 
    } 
} 

你應該注意到,我已經嵌套了$檢查的第一內第二次檢查。我還假設你在原始問題的底部留下了一個右括號?

+0

非常感謝!我現在就來! – user1658549