Skip to content

Instantly share code, notes, and snippets.

@fredleger
Last active November 3, 2017 21:56
Show Gist options
  • Save fredleger/8d13be5ffe3da4d961e5d32470f10e10 to your computer and use it in GitHub Desktop.
Save fredleger/8d13be5ffe3da4d961e5d32470f10e10 to your computer and use it in GitHub Desktop.
#!/bin/bash -x
# --------------------------------------------------
# stop a synology nas using ssh and poweroff
# --------------------------------------------------
CURRENTDIR=$(dirname $(realpath $0))
HOST=${1:-192.168.77.2}
USER=${2:-admin}
SSHPRIVATEKEY=${3:-$CURRENTDIR/syno.priv}
SSH_EXTRA_ARGS="-q -o StrictHostKeyChecking=no"
#CMD="sudo poweroff"
CMD="sudo /bin/bash -c 'echo 1 >/dev/ttyS1'"
if [ $(ping -c 1 ${HOST} > /dev/null && echo $?) ]; then
ssh ${SSH_EXTRA_ARGS} -i ${SSHPRIVATEKEY} ${USER}@${HOST} ${CMD}
exit $?
else
echo "Host is not alive, skipping it..."
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment