linux_wiki:command_many_systems_part2_send_cmd

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
linux_wiki:command_many_systems_part2_send_cmd [2016/12/09 16:53]
billdozor [Main Script File]
linux_wiki:command_many_systems_part2_send_cmd [2016/12/09 16:54]
billdozor [Worker Script File]
Line 491: Line 491:
 # Name: worker_send-cmd.sh # Name: worker_send-cmd.sh
 # Description: Worker script for the parent "send-cmd.sh" # Description: Worker script for the parent "send-cmd.sh"
-# Last Updated: 2016-11-25 +# Last Updated: 2016-12-09 
-# Recent Changes:-File rename +# Recent Changes:-Added return code to output; newline after output;  
-##############################################################+#                 color to return code output 
 +#                -Moved 'Working on...' output to parent script 
 +####################################################################################
  
 if [[ -z ${1} ]]; then if [[ -z ${1} ]]; then
Line 500: Line 502:
   exit 1   exit 1
 fi fi
 +
 +## Configure colors ##
 +# End/reset color
 +color_end='\033[0m'
 +
 +# Colors
 +color_green='\033[0;32m'
 +color_red='\033[0;31m'
 +color_yellow='\033[0;33m'
 +## End of configure colors ##
  
 # Set system name to the first argument # Set system name to the first argument
Line 509: Line 521:
  
 # Send command to system and capture output # Send command to system and capture output
-echo "-> Working on ${system_name}..." 
 output="$(ssh -qt -o ConnectTimeout=5 ${system_name} "${send_cmd}")" output="$(ssh -qt -o ConnectTimeout=5 ${system_name} "${send_cmd}")"
 +return_code=$(echo $?)
  
-Show formatted output +case "${return_code}" in 
-echo -e ">> Returned output from ${system_name}:\n${output}"+  0) 0 return code - show green return code 
 +    echo -e "-> ${system_name} (${color_green}retcode=${return_code}${color_end})\n${output}\n" 
 +  ;; 
 + 1) # 1 return code  - show red return code 
 +    echo -e "-${system_name} (${color_red}retcode=${return_code}${color_end})\n${output}\n" 
 +  ;; 
 + *) # any other return code  - show yellow return code 
 +    echo -e "-> ${system_name} (${color_yellow}retcode=${return_code}${color_end})\n${output}\n" 
 +  ;; 
 +esac
 </code> </code>
  
 ---- ----
  
  • linux_wiki/command_many_systems_part2_send_cmd.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)