linux shell中telnet远程重启服务器
telnet_remoto.sh
--------- begin -----------
#!/bin/bash
(
sleep 30
echo 'username' # username
sleep 25
echo 'passwd' # password
sleep 25
echo 'su -' # command
sleep 30
echo 'root_passwd'
sleep 25
echo 'echo "" 2>&1 >> /root/cron_remoto.log'
sleep 2
echo 'echo system rebooting... 2>&1 >> /root/cron_remoto.log'
sleep 2
echo 'echo "" 2>&1 >> /root/cron_remoto.log'
sleep 2
echo 'echo -------------------- 2>&1 >> /root/cron_remoto.log'
sleep 2
echo 'reboot'
sleep 30
) | telnet remoto_ip_addr # telnet IP
--------- end -----------
Login timed out after 60 seconds
登陆默认时限60秒
chmod 755 telnet_remoto.sh
将telnet_remoto.sh加入crontab中,可实现定时重启远程服务器;
将reboot改为其他命令,也可适用于远程服务器crond服务未安装
或服务失效情况下定时执行shell脚本。