title: Linux Bash Script And Mongo
body: <p>I have a bash script to check a MongoDB database and send an email if certain conditions are met.</p>
  
  <p>Mongo give you the <a href="http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/#eval-option" rel="nofollow"><strong>--eval</strong></a> option to return a value. But instead to have something like:</p>
  
  <p>ALERT=true|false</p>
  
  <p>I have:</p>
  
  <p>ALERT= MongoDB shell version: 2.6.1</p>
  
  <pre><code> #!/bin/bash
   echo "WatchDog Jerry"
  
   ALERT=$(mongo ob --eval 'var now = new Date().getTime(), alert = false; db.sess.find().forEach(function(sess){ var delay = 1 * 60 * 1000; var ts = sess.ts.toNumber(); if((now - ts) &gt; delay) alert = true;});  print(alert);')
  
   echo "alert: $ALERT"
  
   if [ "$ALERT" == "true" ]; then
       mail -s "ALARM - WatchDog Jerry" marco@test.com  &lt; /root/watchdog/email
   fi
  </code></pre>
  
  <p>Can someone help me? 
  What I need is to assign the js variable 'alarm' to the bash variable ALARM</p>