- 论坛徽章:
- 0
|
我已经写好了一个脚本,但是不知道怎么能把IP定义一个数组,然后分别去远程SCP执行命令,目前是一个一个IP改脚本反复执行的,实在是太笨了。- #!/usr/bin/expect -f
- set remote "192.168.137.100"
- set local "192.168.137.102"
- set passwd "123456"
- set passwd1 "qwerty"
- spawn ssh matao@$remote;
- expect {
- "*yes/no*" { send "yes\r"; exp_continue}
- "*password*" { send "$passwd2\r" }
- };
- expect "*@*";
- send "su -\r";
- set timeout 10
- expect "*password*";
- send "$passwd\r";
- expect "*@*";
- send "netstat -ntpla |grep LISTEN > /root/aaa.txt\r";
- expect "*@*";
- send "scp /root/aaa.txt root@$local:/root/$iphost.txt\r";
- set timeout 10
- expect {
- "*yes/no" { send "yes\r"; exp_continue }
- "*password*" { send "$passwd\r"; exp_continue }
- };
- expect {
- "*password*" { send "$passwd1\r" }
- };
- expect "*@*";
- send "rm -rf /root/aaa.txt\r";
- expect 100%;
- expect eof;
复制代码 |
|