2014-12-20 56 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