host.text内容
192.168.40.152 123456
192.168.40.182 123456
循环读取文件内容的方法并传递参数
dir=/home/hanson/hsshell/sysLoginSh
while read line
do
host=`echo $line| awk '{print $1}'`
passwd=`echo $line | awk '{print $2}'`
$dir/cpExeShell.sh $host $passwd &
done < $dir/host.txt
将参数传递到cpExeShell中,对应的获取方法
set HOST [lindex $argv 0]
set PASSWD [lindex $argv 1]
spawn ssh root@$HOST
expect "(yes/no)?" { send "yes\n" }
expect "*password:" { send "$PASSWD\n" }
expect "*password:" { send "$PASSWD\n" }
#expect "*#" { send "cd /data/server/apache-tomcat/apache-tomcat8881/bin\n" } #执行相关操作,比如adduser
expect "*#" { send "/home/tomcatRestat.sh\n" } #执行相关操作,比如adduser
expect eof
lindex $argv 0代表第一个参数 根据下标获取参数顺序