Method 1:
#!/bin/bashuser= ' cat iplist.txt ' pass= ' cat Passwd.txt ' echo $USERSSH () {while Truedo x=$1;shift;y=$2//Note s Hift, if the shift operation is not performed, the value of $ $ will not change. /usr/bin/expect <<-eofspawn ssh [email protected] $xexpect "(yes\no)" {send "yes\r" expect Passwordsend "$y \ r"} Expect "*passwd" send "$y \ r" expect "#" send "Touch 2222222\r"
Method 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 06:36:18 PM CST
6 #########################################################################
7 #!/bin/bash
8 user= ' Cat iplist.txt '
9 pass= ' Cat Passwd.txt '
Ten while read X y
One do
12/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 111111111111111111111\r"
Send "logout\r"
Expect EOF
EOF
25
26
done< < (echo "$USER" "$PASS \ n")
28
29
Shell-Script gives multiple data lists to perform tasks