linux 批量更改shell


摘要: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 快速安装

  1. sudo apt-add-repository ppa:ansible/ansible
  2. sudo apt-get update
  3. sudo apt-get install ansible
  4. sudo vim /etc/ansible/hosts (配置)
上一篇:古灵精怪的python——地址,浅拷贝与身份运算符


下一篇:Java 工厂方法模式5