现在有个需要,每次都要去20台服务器上重启相同的处理程序,操作任务重复。现在作用shell脚本来实现自动重启功能。现在使用sshpass来实现简单的命令自动交互。脚本如下
#!bin/bash Passwd=123456 #定义数组,存储ip地址 declare -a IPAddress IPAddress=("10.0.60.102" "10.0.60.103" "10.0.60.202" "10.0.60.203" "10.0.60.215") numsucess=0 numfail=0 #循环遍历数组 for IP in ${IPAddress[@]} do sshpass -p $Passwd ssh -o StrictHostKeyChecking=no $IP /etc/init.d/ProcessCenter-Process $1 &> /dev/null if [ $? -eq 0 ];then echo "host:$IP sucessed." let numsucess=$numsucess+1 else echo "host:$IP failed." let numfail=$numfail+1 fi done echo -e "\033[31m sucess host:$numsucess.\033[0m" echo -e "\033[31m failed host:$numfail. \033[0m"
本文出自 “eagle” 博客,请务必保留此出处http://seneagle.blog.51cto.com/1319845/1676582
原文地址:http://seneagle.blog.51cto.com/1319845/1676582