Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next 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 [2017/01/24 22:24] billdozor [Main Script File] |
||
---|---|---|---|
Line 58: | Line 58: | ||
# Name: send-cmd.sh | # Name: send-cmd.sh | ||
# Description: | # Description: | ||
- | # Last Updated: 2016-12-09 | + | # Last Updated: 2016-12-20 |
- | # Recent Changes: | + | # Recent Changes:-Added interactive mode (-i) |
+ | # | ||
# after output; color to return code | # after output; color to return code | ||
- | # -Added verbose output argument option, default to no | ||
#################################################################################### | #################################################################################### | ||
Line 106: | Line 106: | ||
echo -e " | echo -e " | ||
echo -e " | echo -e " | ||
+ | echo -e " | ||
echo -e " | echo -e " | ||
echo -e "-w num => Set the max workers for parallel mode (default: | echo -e "-w num => Set the max workers for parallel mode (default: | ||
Line 122: | Line 123: | ||
## Default settings ## | ## Default settings ## | ||
+ | # Non-interactive by default | ||
+ | interactive_mode=" | ||
+ | |||
# Do not send to all systems by default | # Do not send to all systems by default | ||
all_systems=" | all_systems=" | ||
Line 132: | Line 136: | ||
## Get command line arguments ## | ## Get command line arguments ## | ||
- | while getopts "hs: | + | while getopts "his: |
case " | case " | ||
h) # -h (help) argument | h) # -h (help) argument | ||
show_usage | show_usage | ||
exit 0 | exit 0 | ||
+ | ;; | ||
+ | i) # -i (interactive) argument | ||
+ | interactive_mode=" | ||
;; | ;; | ||
s) # -s system | s) # -s system | ||
Line 210: | Line 217: | ||
show_usage | show_usage | ||
exit 1 | exit 1 | ||
+ | fi | ||
+ | |||
+ | # Parallel Send and Interactive Mode set: Issue warning | ||
+ | if [[ ${parallel_cmds} == " | ||
+ | echo -e " | ||
+ | interactive_mode=" | ||
fi | fi | ||
Line 309: | Line 322: | ||
# Serial Execution | # Serial Execution | ||
for node in $(echo ${system_name}); | for node in $(echo ${system_name}); | ||
- | | + | |
- | return_code=$(echo $?) | + | # Non-interactive (default) |
- | case " | + | if [[ ${interactive_mode} != " |
- | 0) # 0 return code - show green return code | + | |
- | echo -e "-> ${node} (${color_green}retcode=${return_code}${color_end})\n${output}\n" | + | return_code=$(echo $?) |
- | ;; | + | case " |
- | | + | 0) # 0 return code - show green return code |
- | echo -e "-> ${node} (${color_red}retcode=${return_code}${color_end})\n${output}\n" | + | echo -e "-> ${node} (${color_green}retcode=${return_code}${color_end})\n${output}\n" |
- | ;; | + | ;; |
- | | + | 1) # 1 return code - show red return code |
- | echo -e "-> ${node} (${color_yellow}retcode=${return_code}${color_end})\n${output}\n" | + | echo -e "-> ${node} (${color_red}retcode=${return_code}${color_end})\n${output}\n" |
- | ;; | + | ;; |
- | esac | + | *) # any other return code - show yellow return code |
+ | echo -e "-> ${node} (${color_yellow}retcode=${return_code}${color_end})\n${output}\n" | ||
+ | ;; | ||
+ | esac | ||
+ | |||
+ | else | ||
+ | # Interactive mode set | ||
+ | echo -e "-> ${node}" | ||
+ | ssh -qt -o ConnectTimeout=5 ${node} " | ||
+ | echo | ||
+ | fi | ||
done | done | ||
fi | fi | ||
Line 356: | Line 379: | ||
# Serial Execution | # Serial Execution | ||
for node in $(cat ${system_name}); | for node in $(cat ${system_name}); | ||
- | | + | |
- | return_code=$(echo $?) | + | # Non-interactive (default) |
- | case " | + | if [[ ${interactive_mode} != " |
- | 0) # 0 return code - show green return code | + | |
- | echo -e "-> ${node} (${color_green}retcode=${return_code}${color_end})\n${output}\n" | + | return_code=$(echo $?) |
- | ;; | + | case " |
- | | + | 0) # 0 return code - show green return code |
- | echo -e "-> ${node} (${color_red}retcode=${return_code}${color_end})\n${output}\n" | + | echo -e "-> ${node} (${color_green}retcode=${return_code}${color_end})\n${output}\n" |
- | ;; | + | ;; |
- | | + | 1) # 1 return code - show red return code |
- | echo -e "-> ${node} (${color_yellow}retcode=${return_code}${color_end})\n${output}\n" | + | echo -e "-> ${node} (${color_red}retcode=${return_code}${color_end})\n${output}\n" |
- | ;; | + | ;; |
- | esac | + | *) # any other return code - show yellow return code |
+ | echo -e "-> ${node} (${color_yellow}retcode=${return_code}${color_end})\n${output}\n" | ||
+ | ;; | ||
+ | esac | ||
+ | |||
+ | else | ||
+ | # Interactive mode set | ||
+ | echo -e "-> ${node}" | ||
+ | ssh -qt -o ConnectTimeout=5 ${node} " | ||
+ | echo | ||
+ | fi | ||
done | done | ||
fi | fi | ||
Line 410: | Line 443: | ||
# Serial Execution | # Serial Execution | ||
for node in $(${spacecmd_cmd} group_listsystems ${system_group}); | for node in $(${spacecmd_cmd} group_listsystems ${system_group}); | ||
- | | + | |
- | return_code=$(echo $?) | + | # Non-interactive (default) |
- | case " | + | if [[ ${interactive_mode} != " |
- | 0) # 0 return code - show green return code | + | |
- | echo -e "-> ${node} (${color_green}retcode=${return_code}${color_end})\n${output}\n" | + | return_code=$(echo $?) |
- | ;; | + | case " |
- | | + | 0) # 0 return code - show green return code |
- | echo -e "-> ${node} (${color_red}retcode=${return_code}${color_end})\n${output}\n" | + | echo -e "-> ${node} (${color_green}retcode=${return_code}${color_end})\n${output}\n" |
- | ;; | + | ;; |
- | | + | 1) # 1 return code - show red return code |
- | echo -e "-> ${node} (${color_yellow}retcode=${return_code}${color_end})\n${output}\n" | + | echo -e "-> ${node} (${color_red}retcode=${return_code}${color_end})\n${output}\n" |
- | ;; | + | ;; |
- | esac | + | *) # any other return code - show yellow return code |
+ | echo -e "-> ${node} (${color_yellow}retcode=${return_code}${color_end})\n${output}\n" | ||
+ | ;; | ||
+ | esac | ||
+ | |||
+ | else | ||
+ | # Interactive mode set | ||
+ | echo -e "-> ${node}" | ||
+ | ssh -qt -o ConnectTimeout=5 ${node} " | ||
+ | echo | ||
+ | fi | ||
done | done | ||
fi | fi | ||
Line 457: | Line 500: | ||
# Serial Execution | # Serial Execution | ||
for node in $(${spacecmd_cmd} system_list); | for node in $(${spacecmd_cmd} system_list); | ||
- | output=" | + | |
- | return_code=$(echo $?) | + | if [[ ${interactive_mode} != " |
- | case " | + | |
- | 0) # 0 return code - show green return code | + | return_code=$(echo $?) |
- | echo -e "-> ${node} (${color_green}retcode=${return_code}${color_end})\n${output}\n" | + | case " |
- | ;; | + | 0) # 0 return code - show green return code |
- | | + | echo -e "-> ${node} (${color_green}retcode=${return_code}${color_end})\n${output}\n" |
- | echo -e "-> ${node} (${color_red}retcode=${return_code}${color_end})\n${output}\n" | + | ;; |
- | ;; | + | 1) # 1 return code - show red return code |
- | | + | echo -e "-> ${node} (${color_red}retcode=${return_code}${color_end})\n${output}\n" |
- | echo -e "-> ${node} (${color_yellow}retcode=${return_code}${color_end})\n${output}\n" | + | ;; |
- | ;; | + | *) # any other return code - show yellow return code |
- | esac | + | echo -e "-> ${node} (${color_yellow}retcode=${return_code}${color_end})\n${output}\n" |
+ | ;; | ||
+ | esac | ||
+ | |||
+ | else | ||
+ | # Interactive mode set | ||
+ | echo -e "-> ${node}" | ||
+ | ssh -qt -o ConnectTimeout=5 ${node} " | ||
+ | echo | ||
+ | fi | ||
done | done | ||
fi | fi | ||
Line 491: | Line 543: | ||
# Name: worker_send-cmd.sh | # Name: worker_send-cmd.sh | ||
# Description: | # Description: | ||
- | # 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 ' | ||
+ | ###################### | ||
if [[ -z ${1} ]]; then | if [[ -z ${1} ]]; then | ||
Line 500: | Line 554: | ||
exit 1 | exit 1 | ||
fi | fi | ||
+ | |||
+ | ## Configure colors ## | ||
+ | # End/reset color | ||
+ | color_end=' | ||
+ | |||
+ | # Colors | ||
+ | color_green=' | ||
+ | color_red=' | ||
+ | color_yellow=' | ||
+ | ## End of configure colors ## | ||
# Set system name to the first argument | # Set system name to the first argument | ||
Line 509: | Line 573: | ||
# Send command to system and capture output | # Send command to system and capture output | ||
- | echo "-> Working on ${system_name}..." | ||
output=" | output=" | ||
+ | return_code=$(echo $?) | ||
- | # Show formatted | + | case " |
- | echo -e ">> Returned | + | 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 | ||
+ | | ||
+ | ;; | ||
+ | *) # any other return code - show yellow return code | ||
+ | echo -e " | ||
+ | ;; | ||
+ | esac | ||
</ | </ | ||
---- | ---- | ||