Mar*_*ali 4 linux bash shell mongodb
我有一个bash脚本来检查MongoDB数据库并在满足某些条件时发送电子邮件.
Mongo为你提供了--eval选项来返回一个值.但相反,有类似的东西:
ALERT = TRUE | FALSE
我有:
ALERT = MongoDB shell版本:2.6.1
#!/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) > delay) alert = true;}); print(alert);')
echo "alert: $ALERT"
if [ "$ALERT" == "true" ]; then
mail -s "ALARM - WatchDog Jerry" marco@test.com < /root/watchdog/email
fi
Run Code Online (Sandbox Code Playgroud)
有人能帮我吗?我需要的是将js变量'alarm'分配给bash变量ALARM