bash-com/trigger-send

31 lines
1008 B
Plaintext
Raw Permalink Normal View History

#!/bin/bash
#!/bin/bash
# (1) Init.
#--------------------------------------------------------#
# (1) Get current absolute dir
ROOT=$(dirname `realpath $0`);
# (2) Check argc
test $# -lt 2 && echo -e "error: too fewarguments\n\n\e[1mUSAGE\e[0m\n\ttrigger-send <key> <host> <port>\n\n\e[1mARGUMENTS\e[0m\n\t<key>\tThe key of the trigger\n\t<host>\tThe host to send the trigger to\n\t<port>\tThe port to send the trigger to\n" && exit 1;
# (3) Check @PORT range #
MIN_PORT=1024;
MAX_PORT=49151;
test "$3" -gt "$MAX_PORT" -o "$3" -lt "$MIN_PORT" && echo "error: <port> must be between $MIN_PORT and $MAX_PORT" && exit 1;
# (4) Set argument explicit names #
TRIGGER_KEY="$1";
TRIGGER_HOST="$2";
TRIGGER_PORT="$3";
# (2) Send trigger signal
#--------------------------------------------------------#
echo "+ connecting to $TRIGGER_HOST:$TRIGGER_PORT";
bash -c "exec 4>/dev/tcp/$TRIGGER_HOST/$TRIGGER_PORT; echo -n \"$TRIGGER_KEY\" >&4; ";
echo " + message '$TRIGGER_KEY' sent";
echo "+ close connection";