Skip to content

Instantly share code, notes, and snippets.

@solocommand
Created January 30, 2017 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solocommand/1c82374bd0d41e96795572e98bdb74b0 to your computer and use it in GitHub Desktop.
Save solocommand/1c82374bd0d41e96795572e98bdb74b0 to your computer and use it in GitHub Desktop.
Continually execute mongo JS
#!/bin/bash
function error {
echo -e "\033[91mAn error was encountered! $1\033[0m"
exit 1
}
if [ "$#" -ne 2 ]; then
error "Usage: mongoupdate DATABASE SCRIPT"
fi
MONGO_HOST="localhost"
DATABASE=$1
SCRIPT=$2
if [ ! -e $SCRIPT ]; then
error "File $SCRIPT does not exist!"
fi
echo -e "\033[32mExecuting $SCRIPT on $DATABASE\033[0m"
COMMAND="mongo $MONGO_HOST/$DATABASE $SCRIPT"
watch -n0.5 $COMMAND
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment