每天给所有的主机更改一个随机密码:
在模版机上:
vim gm.expect
#!/usr/bin/expect
set host [lindex $argv 0]
set passwd [lindex $argv 1]
set cm [lindex $argv 2]
spawn ssh root@$host
expect {
"yes/no" { send "yes\r"; exp_continue}
"password:" { send "$passwd\r" }
}
expect "]*"
send "passwd\r"
expect "assword:"
send "$cm\r"
expect "new password:"
send "$cm\r"
expect "]*"
send "exit\r"
写一个shell脚本
vim gm.sh
#!/bin/bash
if [ ! -f /tmp/zidongmima ]
then
echo “原始密码” > /tmp/zidongmima
fi
passwd=linux$RANDOM
echo $passwd >> /tmp/zidongmima
passwd2=tail -2 zidongmima |sed -n ‘1’p
for ip in `cat ip.txt`
do
echo $ip
sh gm.expect $ip $passwd2 $passwd
done
然后把我们的shell脚本加入到计划任务中就可以了
在模版机上:
vim gm.expect
#!/usr/bin/expect
set host [lindex $argv 0]
set passwd [lindex $argv 1]
set cm [lindex $argv 2]
spawn ssh root@$host
expect {
"yes/no" { send "yes\r"; exp_continue}
"password:" { send "$passwd\r" }
}
expect "]*"
send "passwd\r"
expect "assword:"
send "$cm\r"
expect "new password:"
send "$cm\r"
expect "]*"
send "exit\r"
写一个shell脚本
vim gm.sh
#!/bin/bash
if [ ! -f /tmp/zidongmima ]
then
echo “原始密码” > /tmp/zidongmima
fi
passwd=linux$RANDOM
echo $passwd >> /tmp/zidongmima
passwd2=tail -2 zidongmima |sed -n ‘1’p
for ip in `cat ip.txt`
do
echo $ip
sh gm.expect $ip $passwd2 $passwd
done
然后把我们的shell脚本加入到计划任务中就可以了
编辑回复