期望脚本使用ssh更改密码

时间:2014-10-30 13:43:22

标签: expect

任何人都可以帮助解决下面脚本的问题吗?它说密码修改成功,但密码仍然是旧密码。我正在运行此脚本来更改检查点SPLAT防火墙专家密码,该密码使用ssh直接登录到专家模式。

#!/usr/bin/expect
set username admin
set oldpass sam$$$
set newpass abc.123

spawn ssh -l $username 192.168.1.10

expect "assword:"
send "$oldpass\r"
expect "# "
sleep 1
send "passwd\r"
expect "Enter new expert password:"
send "$newpass\r"
expect "Enter new expert password (again):"
send "$newpass\r"
expect eof"
expect "# "
send "exit\n"


[admin@localhost ~]$ ./test.sh
spawn ssh -l admin 192.168.1.10
admin@192.168.1.10's password:
Last login: Thu Oct 30 18:41:52 2014 from 192.168.1.5
[Expert@cpmodule]# passwd
Enter new expert password:
Enter new expert password (again):
Expert password has been changed

1 个答案:

答案 0 :(得分:0)

检查一下,这对我有用。

#!/usr/bin/expect
set timeout 20
set user user2
set password abc123
set new bac234qwe.1
set ip localhost
spawn -noecho ssh -q -o StrictHostKeychecking=no "$user\@$ip" "passwd"
expect "assword:"
send "$password\r"
expect "*UNIX password:"
send "$password\r"
expect "New password: "
send "$new\r"
expect "Retype new password:"
send "$new\r"
相关问题