Skip to content

Instantly share code, notes, and snippets.

@gempesaw
Last active January 2, 2019 08:57
Show Gist options
  • Select an option

  • Save gempesaw/7874698 to your computer and use it in GitHub Desktop.

Select an option

Save gempesaw/7874698 to your computer and use it in GitHub Desktop.
convenience shell scripts for sauce connect
#! /bin/bash
: ${SAUCE_USER:?"Need to set SAUCE_USER:
export SAUCE_USER=<your sauce username>"}
: ${SAUCE_KEY:?"Need to set SAUCE_API_KEY:
export SAUCE_KEY=<your sauce api key>"}
MAIL=your@email.com
COMMAND=0
SAUCE_VERSION=sc-4.3.5-linux
if [ "$1" == "update" ] ; then
COMMAND=1
killall java -u $LOGNAME
sleep 10
rm -rf $HOME/sauceConnect
cd
mkdir $HOME/sauceConnect
cd $HOME/sauceConnect
SC=sc.tar.gz
curl https://saucelabs.com/downloads/$SAUCE_VERSION.tar.gz -o $SC
tar -xvf $SC
rm $SC
fi
if [ "$1" == "restart" ] ; then
COMMAND=1
echo "Killing all sauceConnect belonging to $LOGNAME and waiting for them to shut down"
ps aux | grep \[s\]auceConnect | awk '{print $2 }' | xargs kill
echo "Sleeping to let tunnels die"
sleep 10
echo "Starting a new tunnel."
nohup $HOME/sauceConnect/$SAUCE_VERSION/bin/sc -u $SAUCE_USERNAME -k $SAUCE_ACCESS_KEY --shared-tunnel > $HOME/$SAUCE_USERNAME &
fi
if [ "$1" == "crontab" ] ; then
COMMAND=1
(echo "MAILTO=\"$MAIL\"
00 20 * * * rm $HOME/sauce_connect.log $HOME/$SAUCE_USERNAME > /dev/null
00 7,12,17,20 * * * $HOME/sauce restart > /dev/null
01 7,12,17,20 * * * $HOME/sauce status > /dev/null
*/10 * * * * $HOME/sauce monitor > /dev/null
") | crontab
fi
if [ "$1" == "status" ] ; then
COMMAND=1
TUNNEL=$(curl --silent --insecure https://$SAUCE_USERNAME:$SAUCE_ACCESS_KEY@saucelabs.com/rest/v1/$SAUCE_USERNAME/tunnels)
echo "Sauce Tunnel Status: $TUNNEL"
echo "
Running Sauce Tunnels on this box:"
ps aux | grep Sauce | grep -v grep
echo "
Current Crontab:"
(crontab -l) | cat
fi
if [ "$1" == "monitor" ] ; then
COMMAND=1
TUNNEL=$(curl --silent --insecure https://$SAUCE_USERNAME:$SAUCE_ACCESS_KEY@saucelabs.com/rest/v1/$SAUCE_USERNAME/tunnels)
echo "$(date): $TUNNEL" >> $HOME/monitor_log
fi
HELP="Usage: ./sauce COMMAND
Control your sauce tunnel.
The commands you can use are:
help Show this help
restart Kill all java processes belonging to the user and
nohup the sauce tunnel, stdout redirected to
$HOME/$SAUCE_USERNAME
crontab Write over the crontab with the default Sauce-tasks
only crontab
status View the running Sauce tunnels and the current crontab
update Download a new version of the Sauce Connect jar in
~/sauceConnect. You'll want to run ./sauce restart
after this to start the tunnel again
monitor Check the status and echo it to a file in the home dir
"
if [ "$1" == "help" ] || [ "$1" == "--help" ] || [ "$1" == "-h" ] || [ $COMMAND -eq 0 ] ; then
echo "$HELP" > $HOME/README
echo "$HELP"
fi
Usage: ./sauce COMMAND
Control your sauce tunnel.

The commands you can use are:

   help         Show this help

   restart      Kill all java processes belonging to the user and
                nohup the sauce tunnel, stdout redirected to
                $HOME/$SAUCE_USERNAME

   crontab      Write over the crontab with the default Sauce-tasks
                only crontab

   status       View the running Sauce tunnels and the current crontab

   update       Download a new version of the Sauce Connect jar in
                ~/sauceConnect. You'll want to run ./sauce restart
                after this to start the tunnel again

   monitor      Check the status and echo it to a file in the home dir
@gempesaw
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment