zoukankan      html  css  js  c++  java
  • ssh执行命令

    #!/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 '-------------------------'
    

      

    ssh执行命令

  • 相关阅读:
    Windows7共享设置
    13-运算符
    13-数据类型转换
    06-移动web之flex布局
    09-sass
    08-less预处理器
    移动端必须掌握知识点
    11-JS变量
    10-响应式
    07-rem
  • 原文地址:https://www.cnblogs.com/jcici/p/13140783.html
Copyright © 2011-2022 走看看