1.实现ssh自动登录完成任务的expect脚本
[root@localhost shell]# cat login.exp
#!/usr/bin/expect -f
set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 30
spawn ssh
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "$passwd\r" }
}
expect "]*"
send "mkdir -p /tmp/haha\r"
send "exit\r"
2.调用login.exp完成批量管理
#!/bin/bash
for i in `awk '{print $1}' passwd.txt`
do
j=`awk -v I="$i" '{if(I==$1)print $2}' passwd.txt`
expect /root/shell/login.exp $i $j
done
3.passwd.txt
192.168.0.2 password2
192.168.0.3 password3
阅读(368) | 评论(0) | 转发(0) |