2010-12-21 124 views
-1

我有一个脚本,需要在我的Subversion存储库中的各个分支之间切换才能执行副本。这导致必须重复输入密码。现在,一旦我完成了这一段时间,并且我很熟悉我的剧本。我搞砸了,引起我很大的愤怒。期望重复输入用户名和密码的脚本

我已经使用期望在提示之前输入密码。我希望能够学习如何一次又一次地运行多次密码提示,直到任务完成。

到目前为止,这是我的。

#!/usr/bin/expect 
global env 
set timeout 10 
spawn command that requires password 
expect "^user" 
send "password\r" 
#i need this to repeat over and over until the prompt stops showing up. 

请谢谢。

回答

2

天真,蛮力方法:

while 1 { 
    expect $prompt 
    send $password\r 
} 

更好:

expect { 
    $prompt { 
     send $password\r 
     exp_continue 
    } 
    timeout { 
     puts "haven't seen prompt for $timeout seconds" 
    } 
    "some pattern that indicates password no longer required" 
} 
puts "continuing ..." 
5

你有没有想过使用ssh keys所以你不必一遍又一遍地输入密码?

+0

SSH密钥不工作,我有他们的设置,但它并不想进行检查,当我运行此命令。 – myusuf3 2010-12-21 16:17:52