#!/bin/bash
### << config start ###
username="root"
password="123456"
ip_list=("1.1.1.1" "2.2.2.2" "3.3.3.3")
cmd_1="wc -l /root/aaa.txt"
cmd_2="wc -l /root/bbb.txt"
### >> config end ###
# restart all machine
remote_exec_command(){
/usr/bin/expect <<EOF
set timeout 30
spawn scp $2 $user_name@$1:/root
expect {
"*yes/no" {send "yes\r";exp_continue}
"*password:" {send "$password\r"}
}
expect eof
EOF
sshpass -p $password ssh $username@$1 $my_cmd
}
for ip in ${ip_list[@]};
do
my_cmd=$cmd_1
remote_exec_command $ip aaa.txt
done
my_cmd=$cmd_2
remote_exec_command $ip bbb.txt
echo -e "\nInit env done."