【spawn】远程登录并用普通账户运行命令
#!/bin/bash
#A:S
pro_file=${1}
file_day=$(date "+%Y%m%d%H")
comd="cat /etc/crontab "
restart_fun(){
cat ${pro_file}.txt | while read ipline;
do
ip=`echo $ipline | awk -F',' '{print $1}'`
echo ${ip}
/usr/bin/expect << EOF
spawn /usr/bin/ssh -t -p 22088 -oStrictHostKeyChecking=no sms@${ip}
expect {
"*assword*" { send "Eastcom@!@#\n" }
}
expect {
"*]*" { send " ${comd} \n" }
}
expect {
"*]*" { send " exit \n" }
}
expect eof
EOF
done
}
restart_fun