方法1:
#!/bin/bash USER=`cat iplist.txt` PASS=`cat passwd.txt` echo $USER SSH() { while true do x=$1;shift;y=$2 //注意shift, 如果不进行移位操作,$1的值就不会变。 /usr/bin/expect <<-EOF spawn ssh [email protected]$x expect "(yes\no)" { send "yes\r" expect password send "$y\r" } expect "*passwd" send "$y\r" expect "#" send "touch 2222222\r"
方法2:
send "logout\r"
expect eof
EOF
done
}
SSH $USER $PASS 1 #########################################################################
2 # File Name: 1.sh
3 # Author: dty
4 # mail: [email protected]
5 # Created Time: Sat 15 Aug 2015 06:36:18 PM CST
6 #########################################################################
7 #!/bin/bash
8 USER=`cat iplist.txt`
9 PASS=`cat passwd.txt`
10 while read x y
11 do
12 /usr/bin/expect <<-EOF
13 spawn ssh [email protected]$x
14 expect "(yes\no)" {
15 send "yes\r"
16 expect password
17 send "$y\r" }
18 expect "*passwd"
19 send "$y\r"
20 expect "#"
21 send "touch 111111111111111111111\r"
22 send "logout\r"
23 expect eof
24 EOF
25
26
27 done< <(echo "$USER" "$PASS\n")
28
29