Changeset 416


Ignore:
Timestamp:
Nov 24, 2019, 5:40:06 PM (4 years ago)
Author:
g7moreau
Message:
  • Add support for parallel and xargs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tssh/tssh

    r392 r416  
    2121
    2222OPTIONS
    23    -w             windows to open (integer, default 16)
     23   -w windows     windows to open (integer, default 16)
    2424   -o ssh_option  option to pass to ssh
    2525   -f             fast, no nmap scan to eliminate sleeping computer
    2626   -v             verbose
    2727   -c remote_cmd  launch the remote command on hosts and exit
     28   -p             launch in parallel (only with -c) with command parallel or xargs
    2829   -h             help
    2930
     
    120121# get options
    121122if [ $# -eq 0 ]; then usage; exit 1; fi
    122 while getopts "w:o:c:fvh" options
     123while getopts "w:o:c:fvph" options
    123124do
    124125   case ${options} in
     
    139140            usage
    140141            exit 2
    141          fi
     142         fi         
     143         ;;
     144      p)
     145         export parallel='yes'
    142146         ;;
    143147      o)
     
    246250done
    247251
     252if [ "${parallel}" == 'yes' -a -n "${remote_command}" ]
     253then
     254   if which parallel > /dev/null
     255   then
     256      sort -u "/tmp/${base_path}/master++" | parallel -j ${split_number} "ssh ${ssh_option} {} ${remote_command}"
     257   else
     258      sort -u "/tmp/${base_path}/master++" | xargs -n 1 -P ${split_number} -I{} ssh ${ssh_option} {} "${remote_command}"
     259   fi
     260
     261   # Clean temporary folder
     262   [ -d "/tmp/${base_path}" ] && rm -rf "/tmp/${base_path}"
     263   
     264   exit 0
     265fi
     266
     267
    248268# split master list in paquet of split_number computer
    249269sort -u "/tmp/${base_path}/master++" | split -l ${split_number} - /tmp/${base_path}/__splitted_
Note: See TracChangeset for help on using the changeset viewer.