zoukankan      html  css  js  c++  java
  • shell同时执行在多个linux上

    https://blog.csdn.net/weixin_33672109/article/details/92378342

    #!/bin/bash                                            
    if [ "$#" -ne 2 ] ; then                               
        echo "USAGE: $0 -f server_list_file cmd"           
        exit -1                                            
    fi                                                     
                                                           
    file_name=$1                                           
    cmd_str=$2                                             
                                                           
    cwd=$(pwd)                                             
    cd $cwd                                                
    serverlist_file="$cwd/$file_name"                      
                                                           
    if [ ! -e $serverlist_file ] ; then                    
        echo 'server.list not exist';                      
        exit 0                                             
    fi                                                     
                                                           
    while read line                                        
    do                                                     
        #echo $line                                        
        if [ -n "$line" ] ; then     
            echo "DOING--->>>>>" $line "<<<<<<<"
            ssh $line $cmd_str < /dev/null > /dev/null                                                                                                         
            if [ $? -eq 0 ] ; then                         
                echo "$cmd_str done!"                      
            else                                           
                echo "error: " $?                          
            fi                                             
        fi                                                 
    done < $serverlist_file 

    使用帮助:

    执行:

    ./all.sh host_file_list  'rm -rf /lctdir/test.txt' 

    host_file_list中为服务器的地址,一行一个,如下:

    192.168.0.100
    192.168.0.101

    192.168.0.102

     'rm -rf /lctdir/test.txt' 为要执行命令,这个命令执行完的效果,就是把三台服务器的/lctdir/test.txt删除了。

  • 相关阅读:
    Day3-spark基本认识
    团队冲刺第九天
    团队冲刺第八天
    团队冲刺第七天
    团队冲刺第六天
    团队冲刺第五天
    团队冲刺第四天
    团队冲刺第三天
    团队冲刺第二天
    团队冲刺第一天
  • 原文地址:https://www.cnblogs.com/Babylon/p/14606751.html
Copyright © 2011-2022 走看看