期望脚本使用 ssh 更改密码

问题描述 投票:0回答:1

任何人都可以帮助解决以下脚本的问题吗?它说密码更改成功,但密码仍然是旧密码。我正在运行这个脚本来更改检查点 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
[email protected]'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
expect
1个回答
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"
© www.soinside.com 2019 - 2024. All rights reserved.