expect 批量安装多台机器
#!/bin/bash
for i in `cat /jiaoben/ipliebiao.txt`
do
m=`echo $i|awk '{print $1}'`
n=`echo $i|awk '{print $2}'`
expect -c "
spawn ssh -o StrictHostKeyChecking=no root@$m df -h
# spawn scp -o StrictHostKeyChecking=no /sh/1214/start1.sh root@$m:/root/
expect {
"*sure*" { send yes\r\n; interact }
"*password:*" { send tigermima\r\n; interact }
eof { exit }
}
exit
"
expect -c "
spawn ssh -o StrictHostKeyChecking=no root@$m du-sh
# spawn scp -o StrictHostKeyChecking=no /sh/aa.txt root@$m:/root/
expect {
"*sure*" { send yes\r\n; interact }
"*password:*" { send tigermima\r\n; interact }
eof { exit }
}
exit
"
done
It may have the strength, but the effort, struggle, worthy of the heart.

浙公网安备 33010602011771号