Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improve the display: add color for fatal or trace.

  • Loading branch information...
commit d3eacab9c55b58ebbd1885ab38c81ea0f80e885b 1 parent 0cac51f
@soarpenguin authored
Showing with 41 additions and 2 deletions.
  1. +7 −0 bashrc/template.sh
  2. +34 −2 bashrc/threads.sh
View
7 bashrc/template.sh
@@ -7,6 +7,12 @@ export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }';
curdir=$(cd "$(dirname "$0")"; pwd);
curdir=$(dirname $(readlink -f "$0"));
+MYNAME="${0##*/}"
+report_err() { echo "${MYNAME}: Error: $*" >&2 ; }
+
+cleanup() { rm -f "tmp.*" ; }
+trap cleanup EXIT
+
#tar -cf - ./* | ( cd "${dir}" && tar -xf - )
#if [[ "${PIPESTATUS[0]}" -ne 0 || "${PIPESTATUS[1]}" -ne 0 ]]; then
# echo "Unable to tar files to ${dir}" >&2
@@ -102,3 +108,4 @@ _print_fatal() {
}
#_print_fatal "Command '$cmd' does not exist!"
+
View
36 bashrc/threads.sh
@@ -1,5 +1,34 @@
#!/bin/bash
+MYNAME="${0##*/}"
+report_err() { echo "${MYNAME}: Error: $*" >&2 ; }
+
+if [ -t 1 ]
+then
+ RED="$( echo -e "\e[31m" )"
+ HL_RED="$( echo -e "\e[31;1m" )"
+ HL_BLUE="$( echo -e "\e[34;1m" )"
+
+ NORMAL="$( echo -e "\e[0m" )"
+fi
+
+_hl_red() { echo "$HL_RED""$@""$NORMAL";}
+_hl_blue() { echo "$HL_BLUE""$@""$NORMAL";}
+
+_trace() {
+ echo $(_hl_blue ' ->') "$@" >&2
+}
+
+_print_fatal() {
+ echo $(_hl_red '==>') "$@" >&2
+}
+
+usage() { _print_fatal "Usage: bash ${MYNAME} hostlist."; }
+if [ $# -lt 1 ] || [ ! -e "$1" ]; then
+ usage
+ exit 1
+fi
+
g_HOST_LIST=$1
g_THREAD_NUM=300
tmp_file="pipe.$$"
@@ -16,7 +45,10 @@ mkfifo ${tmp_file}
exec 9<>${tmp_file}
#trap "rm -f ${tmp_file}; exit" INT TERM EXIT
-trap 'rm -f "${tmp_file}"; exit $?' INT TERM EXIT
+cleanup() { rm -f "${tmp_file}" ; }
+trap cleanup EXIT TERM EXIT;
+
+#trap 'rm -f "${tmp_file}"; exit $?' INT TERM EXIT
for ((i=0;i<${g_THREAD_NUM};i++))
do
@@ -26,7 +58,7 @@ done
unset HOST
for HOST in `cat ${g_HOST_LIST}`
do
- echo "start ${HOST} ......"
+ _trace "start ${HOST} ......"
read <&9
(${SSH} ${HOST} "ls " &> log/${HOST}; echo >&9) &
Please sign in to comment.
Something went wrong with that request. Please try again.