diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2020-06-08 05:08:14 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2020-06-08 05:08:14 +0200 |
commit | 23bd461efadf946c5266a535a9bc3294e2ca7147 (patch) | |
tree | 0b51dc050bf2c165b96bb6885ab4dce85c63c8f1 | |
parent | 2752f4a462004485afb6a5486375447b10cd7c36 (diff) | |
download | ltask-23bd461efadf946c5266a535a9bc3294e2ca7147.tar.gz |
Added interactive mode
-rwxr-xr-x | ltask | 38 |
1 files changed, 33 insertions, 5 deletions
@@ -75,6 +75,24 @@ function parse_args() { done } +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() { cat << EOF Usage: @@ -90,8 +108,16 @@ EOF } function interactive() { - perror Interactive mode TODO - exit 1 + 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[$?]} } parse_args @@ -123,7 +149,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 +170,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 |