您的位置:首页 > 其它

expect结合远程操作脚本

2014-01-23 11:08 134 查看
远程执行命令的脚本与expect结合

#!/bin/bash
read -p "请输入你要执行的命令: " file
read -p "是否进行 $file 命令操作(y/n):" fs
passwd=123456 #这是服务器的密码
case $fs in
y)
for i in `cat ip.txt`
do
expect -c "
set timeout -1
spawn ssh root@$i $file
expect {
\"yes/no\" {send \"yes\r\";exp_continue}
\"*password\" {send \"$passwd\r\;exp_continue}
\"root@*\" {send "free -l \r"}
}"
done
;;
*)
exit ;;
esac
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  case expect 远程操作
相关文章推荐