作用: 

1. 可以在执行脚本过程中免输入yes 

2.可以在执行脚本过程中免输入密码

脚本内容如下:  

***  ipfile.txt  为主机列表

[root@YZSJHL-N1-1 opt]# cat remote.sh

#!/usr/bin/expect -f

#chmod 777 distribute_file.sh

password=xxxxxx
path=$1
topath=$2

while read -r ipline
do

expect<<-END
#spawn scp -qpr $path root@${ipline}:${topath}
spawn ssh root@${ipline} "sh /opt/opmysql.sh"
expect {
"(yes/no)?" {send "yes\r"; exp_continue}
"${ipline}'s password:" {send "${password}\r"}
"Permission denied" { send_user "[exec echo "\nError: Password is wrong\n"]"; exit}
}
expect eof
exit
END
done < ipfile.txt

 

相关文章:

  • 2021-07-31
  • 2021-07-17
  • 2022-03-09
  • 2021-08-15
  • 2021-07-26
  • 2021-12-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2020-03-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案