#!/bin/bash #----------------------------------- #Author: panb ##此脚本用来向openresty服务器执行命令 #----------------------------------- set -e Usage(){ echo "Usage: $0 host1 host2 ... 'command'" } if [ $# -lt 2 ];then Usage exit 0 else cmd=${!#} fi i=1 success=0 failed=0 for ip in $@;do if [ $i -eq $# ];then break fi ssh -i ops-ibox.pem root@$ip "$cmd" if [ $? -eq 0 ];then success=$(($success+1)) echo -e " 33[32m$ip | success 33[0m " #cat $logfile else ((failed++)) echo -e " 33[31m$ip | failed 33[0m " #cat $logfile fi ((i++)) done echo -e ' -------------------------' echo -e " 33[32msuccess: $success | failed: $failed 33[0m" echo '-------------------------'