#! /bin/bash
sh-cmd1
....
sh-cmdn
##################
expect <<\EOF
expect-cmd1
.......
expect-cmdn
EOF
##################
sh-cmdo
.......
sh-cmdp
##################
expect <<\EOF
expect-cmdr
.......
expect-cmds
EOF
##################
................
例:
[root@rhvm1 expect]# cat sshcmd2.sh
#!/bin/bash
#. ./timeout.sh
cat /dev/null > ./sshresult.txt
for name in $1
do
echo "[$name] machine's info:" | tee -a ./sshresult.txt
echo"" | tee -a ./sshresult.txt
user=$2
passwd=$3
cmd=$4
expect <set timeout 10
#set host [lindex $argv 0]
#set user [lindex $argv 1]
#set passwd [lindex $argv 2]
#set cmd [lindex $argv 3]
spawn ssh "$cmd"
expect {
"*no" { send "yes\r";exp_continue }
"*assword:*" { send "$passwd\n" }
}
expect eof
EOF
echo "" | tee -a ./sshresult.txt
echo "" | tee -a ./sshresult.txt
echo -------------------------------------------------------------------------- | tee -a ./sshresult.txt
done
[root@rhvm1 expect]#
阅读(1156) | 评论(0) | 转发(0) |