Featured post

Fixed Income Trading: New venues

A simple question came up recently in a conversation – how many new Fixed Income trading venues are there?  I could not think of anywhere th...

Monday, 23 March 2015

Kill MongoDB on OS X in a bash script

The documentation for MongoDB has a little gotcha On OS X the command
$ mongo --shutdown  is not supported.  

The way to work around this is good old fashioned unix geekery, to run ps, grep for [m]ongodb and then awk to just return the pid and not the pid and comm.
As shown below:


#!/bin/sh
echo "Script running in `dirname $0`"
echo "Present working directory $PWD"
TPROC="$(ps -A -o pid,comm | grep [m]ongodb | awk '{print$1}')"
if [ -z "$TPROC" ]
then
  echo "\$TPROC is null. So there is no running instance of mongod"
else
  echo "\$TPROC is NOT null."
  echo "$TPROC to be killed"
  kill $TPROC
fi
 

No comments:

Post a Comment