I am attempting to write an external monitor to determine which of our three databases is the "master." We need to first ssh to the server and then run a command. This command should return either a 'true' or 'fals'
# Name of the pidfile
# Send signal to the process group to kill our former self and any children
# as external monitors are run with SIGHUP blocked
if [ -f $pidfile ]
kill -9 -`cat $pidfile` > /dev/null 2>&1
echo "$$" > $pidfile
# Remove the IPv6/IPv4 compatibility prefix
node_ip=`echo $1 | sed 's/::ffff://'`
log_file -noappend /var/tmp/mongo_status.log
spawn /bin/ssh firstname.lastname@example.org
send "/bin/mongo -u ******** -p ******** --authenticationDatabase admin --eval 'printjson(db.isMaster())'|grep 'ismaster' | cut -c15-18\r"
if [ $status -eq 0 ]
# Remove the pidfile before the script echoes anything to stdout and is killed by bigd
rm -f $pidfile
# Remove the pidfile before the script ends
rm -f $pidfile
I have been unable to determine the the value from expect.
Any suggestions would be most appreciated.
You need to understand the behaviour of External monitors and stdout
K7444: Requirements for external monitor output
Custom external monitors must observe the following output requirements:
Looking at your script, you have
status=$? echo "$status"
This will terminate the script here, and mark the monitor as "Available".
If you need to log something from the script for development purposes, use *logger* to log into /var/log/ltm