我正在尝试创建一个脚本以非交互式方式更新密码。它在我的笔记本电脑上工作,但在我的服务器上失败。两者都使用 Etch 运行相同的配置。
这是脚本:
#!/usr/bin/expect -f
# Change user passwd
set timeout 30
strace 4
set password [lindex $argv 1]
set old_password [lindex $argv 2]
spawn passwd [lindex $argv 0]
sleep 1
expect "(current) UNIX password: $"
send "$old_password\r"
expect "Enter new UNIX password: $"
send "$password\r"
expect "Retype new UNIX password: $"
send "$password\r"
expect eof
在服务器上,输出如下所示:
myuser@server:~$ /home/myuser/adm/chpasswd myuser NewPasswd OldPasswd
2 lindex $argv 0
1 set username [lindex $argv 0]
2 lindex $argv 1
1 set password [lindex $argv 1]
2 lindex $argv 2
1 set old_password [lindex $argv 2]
1 spawn passwd $username
spawn passwd myuser
1 sleep 1
1 expect "(current) UNIX password: $"
Changing password for myuser
(current) UNIX password: 1 send "$old_password\r"
1 expect "Enter new UNIX password: $"
OldPasswd
Enter new UNIX password: 1 send "$password\r"
1 expect "Retype new UNIX password: $"
NewPasswd
1 send "$password\r"
1 expect eof
Retype new UNIX password: 1 exit 0
所以不起作用,因为这对夫妇期望发送似乎不同步。
但奇怪的是,在我的笔记本电脑上它可以工作:
test@mars:/home/test/adm$ ./chpasswd test NewPasswd OldPasswd
2 lindex $argv 1
1 set password [lindex $argv 1]
2 lindex $argv 2
1 set old_password [lindex $argv 2]
2 lindex $argv 0
1 spawn passwd [lindex $argv 0]
spawn passwd test
1 sleep 1
1 expect "(current) UNIX password: $"
Changing password for test
(current) UNIX password: 1 send "$old_password\r"
1 expect "Enter new UNIX password: $"
OldPasswd
Enter new UNIX password: 1 send "$password\r"
1 expect "Retype new UNIX password: $"
NewPasswd
Retype new UNIX password: 1 send "$password\r"
1 expect eof
NewPasswd
passwd: password updated successfully
1 exit 0
任何想法为什么它在服务器上出错?谢谢