ssh批量关闭/etc/hosts中添加了的机器,可自行修改
#!/bin/bash
while true ;do
host=`awk 'NR>2{print $1}' /etc/hosts | sort -r`
echo "
1. shutdown all hosts
2. reboot all hosts
3. exit
"
read -p "please input option: " option
case $option in
1)
echo "===========shutdown now============"
for hosts in ${host}
do
ssh -f $hosts shutdown -h now && echo -e "\033[32m ${hosts}已关机! \033[0m" || echo -e "\033[31;5m ${hosts}关机失败!! \033[0m"
sleep 1;
done
;;
2)
echo "===========reboot============"
for hosts in ${host}
do
ssh -f $hosts reboot && echo -e "\033[32m ${hosts}已重启! \033[0m" || echo -e "\033[31;5m ${hosts}重启失败!! \033[0m"
sleep 1;
done
;;
3|exit|quit|e|q)
exit;
;;
*)
echo "INput args Error!!"
;;
esac
done