摘要:linux 批量更改密码脚本执行**
批量关机 shell
k=226
for i in `seq 101 150`
do
/usr/bin/expect << EOF
spawn ssh bfadmin@192.168.100.$i
expect "~$ "
send "sudo reboot\r"
expect "password"
send "password\r"
EOF
done
批量改密码
for i in `seq 106 130`
do
/usr/bin/expect << EOF
set timeout 150
spawn ssh bfadmin@192.168.100.$i
expect "*$ "
send "sudo passwd bfadmin\r"
expect "sudo"
send "password"
expect "Enter"
send "password\r"
expect "Retype"
send "passwordnew\r"
expect "*$ "
send "exit\r"
EOF
done
hostname 更改
k=226
for i in `seq 106 130`
do
/usr/bin/expect << EOF
spawn ssh bfadmin@192.168.100.$i
expect "~$ "
send "sudo sed -i 's/ubuntu-$k/ubuntu-$i/g' /etc/hostname\r"
expect "password"
send "P@ssw0rd\r"
expect "~$ "
send "sudo sed -i '2a 192.168.100.$i ubuntu-$i' /etc/hosts\r"
expect "~$ "
send "exit\r"
EOF
k=$[$k+1]
done
ansible 快速安装
- sudo apt-add-repository ppa:ansible/ansible
- sudo apt-get update
- sudo apt-get install ansible
- sudo vim /etc/ansible/hosts (配置)