#!/bin/bash # Name: worker_send-cmd.sh # Description: Worker script for the parent "send-cmd.sh" # Last Updated: 2016-12-09 # 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 echo -e "ERROR! This worker script requires arguments and is meant to be executed via its parent script." echo -e "For usage see: ./send-cmd.sh -h" exit 1 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 system_name="${1}" # Shift arguments and set the command to send as the remaining arguments shift send_cmd="$@" # Send command to system and capture output output="$(ssh -qt -o ConnectTimeout=5 ${system_name} "${send_cmd}")" return_code=$(echo $?) case "${return_code}" in 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