Last active
August 29, 2015 14:25
-
-
Save wrannaman/f2d1e5602535f80557c1 to your computer and use it in GitHub Desktop.
getting sick of stopping your server and hitting sails www when adding new files? Bash to the rescue. Put this in your root folder and run it : $./autorun 60 sudo sails www
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#usage ./autorun 60 sudo sails www | |
function show_help() | |
{ | |
echo "" | |
echo "usage: watch [sleep duration in seconds] [command]" | |
echo "" | |
echo "e.g. To cat a file every second, run the following" | |
echo "" | |
echo " watch 1 cat /tmp/it.txt" | |
exit; | |
} | |
function show_help_if_required() | |
{ | |
if [ "$1" == "help" ] | |
then | |
show_help | |
fi | |
if [ -z "$1" ] | |
then | |
show_help | |
fi | |
} | |
function require_numeric_value() | |
{ | |
REG_EX='^[0-9]+$' | |
if ! [[ $1 =~ $REG_EX ]] ; then | |
show_help | |
fi | |
} | |
show_help_if_required $1 | |
require_numeric_value $1 | |
DURATION=$1 | |
shift | |
while :; do | |
echo "Updating every $DURATION seconds. Last updated $(date)" | |
bash -c "$*" | |
sleep $DURATION | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment