linuxexpect批量修改主机密码

编程

ip.txt

192.168.0.105123455

192.168.0.106123456

192.168.0.107123457

192.168.0.108123458

passwd.sh

#!/bin/bash

for ip in `awk"{print $1}" ip.txt`

do

pass=`grep $ip ip.txt |awk"{print $2}"`

echo $ip $pass

expect action.exp $ip $pass

done

action.exp

#!/bin/expect

set ip [lindex $argv 0]

set passwd [lindex $argv 1]

set timeout 30

spawn ssh root@$ip

expect {

"yes/no" {send "yes";exp_continue}

"password" {send "$passwd"}

}

expect "#"

send "echo 408950 |passwd --stdin root"

send "exit"

expect eof

使用

[root@localhost ~]# shpasswd.sh

192.168.0.105123456

spawn ssh root@192.168.0.105

root@192.168.0.105"s password:

Last login: Tue Jul 722:37:382020 from 192.168.0.104

[root@localhost ~]# echo123456 |passwd --stdin root

Changing password for user root.

passwd: all authentication tokens updated successfully.

[root@localhost ~]# exit

logout

Connection to 192.168.0.105 closed.

 

原文链接:https://www.cnblogs.com/mu2i/archive/2020/07/07/13264102.html

以上是 linuxexpect批量修改主机密码 的全部内容, 来源链接: utcz.com/z/518153.html

回到顶部