Script to dynamically shutdown all Mongod on your box

Here is a quick and dirty script to shutdown all Mongod instances on you vagrant host. This is only to be used for educational purposes and not a production ready script as it has no error checking. Assumption is that the admin user and passwd is same across all your mongod instances. This script works from the directory where conf files are hosted.

vagrant@m103:~$ cat shutdown_all


for prt in cat *.conf | grep port | awk -F":" '{print $2}'


echo “Shutting down mongod on port $prt”

mongo --host “localhost:$prt” -u m103-admin -p m103-pass << EOF

use admin;




echo “Done shutting down all dbs \n”

pidlist=ps -ef |grep mongod | awk '{print $2}'

echo “check following pids to ensure they are not mongod related \n”

echo $pidlist

No need to reinvent the wheel:

  1. killall mongod
  2. pkill mongod


sure kill will work for a learning env.

Acceptable in any environment.