我正在尝试使用期望脚本来更改我在多台服务器上的密码,但是对于如何将服务器列表传递给它,我有点困惑。
我正在使用的脚本如下:
#!/usr/bin/expect -f
# wrapper to make passwd(1) be non-interactive
# username is passed as 1st arg, passwd as 2nd
set username [lindex $argv 0]
set password [lindex $argv 1]
set serverid [lindex $argv 2]
set newpassword [lindex $argv 3]
spawn ssh -t $serverid passwd
expect "assword:"
sleep 3
send "$password\r"
expect "UNIX password:"
sleep 3
send "$password\r"
expect "password:"
sleep 3
send "$newpassword\r"
expect "password:"
sleep 3
send "$newpassword\r"
expect eof
我正在尝试这样运行它:
[blah@blah ~]$ ./setkey1 blah password 'cat serverlist' meh
这给了我以下输出:
spawn ssh -t cat serverid passwd
ssh: cat serverid: Name or service not known
send: spawn id exp6 not open
while executing
"send "$password\r""
(file "./setkey1" line 13)
所以我然后尝试运行以下 for 循环:
[blah@blah ~]$ for i in serverid; do `cat serverid`; ./setkey1 blah password $i meh; done
这给了我以下信息:
-bash: staging01v: command not found
spawn ssh -t serverid passwd
ssh: serverid: Name or service not known
send: spawn id exp6 not open
while executing
"send "$password\r""
(file "./setkey1" line 13)
如果我尝试使用expect 脚本,并且只输入一个服务器名称,它的工作原理就像......嗯......预期的那样。
我究竟做错了什么?