Skip to content

Instantly share code, notes, and snippets.

@squirrel532
Created May 17, 2017 20:25
Show Gist options
  • Save squirrel532/f95c56466cc5204b0fbffb392040355b to your computer and use it in GitHub Desktop.
Save squirrel532/f95c56466cc5204b0fbffb392040355b to your computer and use it in GitHub Desktop.
#!/bin/bash
device=$1
cmd=$2
username="username_on_device"
IDENTITY_FILE="/path/to/key"
case $cmd in
"shutdown") ssh $username@localhost -i $IDENTITY_FILE -p $device -At sudo shutdown -h now ;;
"reboot") ssh $username@localhost -i $IDENTITY_FILE -p $device -At sudo reboot ;;
"shell") ssh $username@localhost -i $IDENTITY_FILE -p $device ;;
"command") ssh $username@localhost -i $IDENTITY_FILE -p $device -At ${@:3} ;;
"push") scp -i $IDENTITY_FILE -P $device $3 $username@localhost:$4 ;;
"pull") scp -i $IDENTITY_FILE -P $device $username@localhost:$3 $4 ;;
"status") ssh $username@localhost -i $IDENTITY_FILE -p $device true > /dev/null 2>&1;
if [ $? == 0 ]; then
echo -e "\x1b[32;1m online \x1b[0m";
else
echo -e "\x1b[31;1m offline \x1b[0m";
fi ;;
"watch") while true; do
d=$(date)
ssh $username@localhost -i $IDENTITY_FILE -p $device true > /dev/null 2>&1;
if [ $? == 0 ]; then
echo -e "$d\x1b[32;1m online \x1b[0m";
else
echo -e "$d\x1b[31;1m offline \x1b[0m";
fi
sleep 2s
done;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment