aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xltask85
1 files changed, 53 insertions, 32 deletions
diff --git a/ltask b/ltask
index 38b507b..d9a8b6a 100755
--- a/ltask
+++ b/ltask
@@ -49,30 +49,22 @@ function perror() {
echo -e $@ 1>&2
}
-function parse_args() {
- for (( i=0; i < $ARGC;i++ )); do
- local ARGREGEX="^-.*"
- if [[ ! ${ARGV[$i]} =~ $ARGREGEX ]]; then
- [ -z $TASK ] && TASK=${ARGV[$i]} && continue
- [ -z $TARGET ] && TARGET=${ARGV[$i]} && continue
-
- print_help 1
- fi
-
- case ${ARGV[$i]} in
- -H)
- i=$((i+1))
- HOSTS+=(${ARGV[$i]});;
- -p)
- PARALLEL="yes";;
- -h)
- print_help 0;;
- *)
- echo Invalid Argument ${ARGV[$i]}
- echo $0 -h for help
- exit 1;;
- esac
+selector()
+{
+ local regex="^-?[0-9]+\$"
+ local cnt=0
+ for selection in "$@"
+ do
+ echo "$cnt) $selection"
+ ((cnt=$cnt + 1))
done
+
+ read -p "(default=0) >" inp
+ if [[ "$inp" =~ $regex ]] && [ $inp -ge 0 -a $inp -le $# ]
+ then
+ return $inp
+ fi
+ return 0
}
function print_help() {
@@ -89,15 +81,42 @@ EOF
exit $1
}
-function interactive() {
- perror Interactive mode TODO
- exit 1
-}
+#Parse args
+for (( i=0; i < $ARGC;i++ )); do
+ ARGREGEX="^-.*"
+ if [[ ! ${ARGV[$i]} =~ $ARGREGEX ]]; then
+ [ -z $TASK ] && TASK=${ARGV[$i]} && continue
+ [ -z $TARGET ] && TARGET=${ARGV[$i]} && continue
+
+ print_help 1
+ fi
-parse_args
+ case ${ARGV[$i]} in
+ -H)
+ i=$((i+1))
+ HOSTS+=(${ARGV[$i]});;
+ -p)
+ PARALLEL="yes";;
+ -h)
+ print_help 0;;
+ *)
+ echo Invalid Argument ${ARGV[$i]}
+ echo $0 -h for help
+ exit 1;;
+ esac
+done
if [ -z $TASK ]; then
- interactive
+ TASK_LIST=( $(ls $TASK_DIR) )
+ TARGET_LIST=( $(ls $TARGET_DIR) )
+
+ perror "\nSelect a Task"
+ >&2 selector ${TASK_LIST[@]}
+ TASK=${TASK_LIST[$?]}
+
+ perror "\nSelect a Target"
+ >&2 selector ${TARGET_LIST[@]}
+ TARGET=${TARGET_LIST[$?]}
fi
unset TASK_ISSET
@@ -123,7 +142,7 @@ for hoststring in "${HOSTS_UNIQUE[@]}"; do
IFS=$':' read hostname port <<< "$hoststring"
[ ! -z $port ] && rexecargs+="-p $port "
- rexecargs+="-i ${SSH_IDENTITY_FILE:=~/.ssh/id_rsa} "
+ [ ! -z $SSH_IDENTITY_FILE ] && rexecargs+="-i $SSH_IDENTITY_FILE "
[ ${#FILES[@]} -gt 0 ] && for f in ${FILES[@]}; do rexecargs+="-f $f "; done
[ ! -z $SSH_USER ] && rexecargs+="$SSH_USER@"
@@ -144,16 +163,18 @@ for hoststring in "${HOSTS_UNIQUE[@]}"; do
done
if [ $PARALLEL = "yes" ]; then
- perror Waiting for remote tasks to finish...
+ perror Waiting for asynchronous tasks to finisch...
+
for hostname in ${!HOST_PID[@]}; do
wait ${HOST_PID[$hostname]}
[ $? -ne 0 ] && FAILED_HOSTS+=($hostname)
done
+
perror Done!
fi
if [ ${#FAILED_HOSTS[@]} -gt 0 ]; then
- perror "\n"
+ perror
perror ${#FAILED_HOSTS[@]} targets failed:
perror ${FAILED_HOSTS[@]}
exit 1