30-Oct-2020 13:20
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'
#!/bin/sh
# Name of the pidfile
pidfile="/var/run/$MONITOR_NAME.$1..$2.pid"
# 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 ]
then
kill -9 -`cat $pidfile` > /dev/null 2>&1
fi
echo "$$" > $pidfile
# Remove the IPv6/IPv4 compatibility prefix
node_ip=`echo $1 | sed 's/::ffff://'`
/bin/expect<<EOF
log_file -noappend /var/tmp/mongo_status.log
spawn /bin/ssh svc_f5_mongo@10.xx.yy.zz
sleep 1;
expect "password:"
send "***********"
expect "svc_f5"
send "/bin/mongo -u ******** -p ******** --authenticationDatabase admin --eval 'printjson(db.isMaster())'|grep 'ismaster' | cut -c15-18\r"
sleep 4
send "exit\r"
EOF
status=$?
echo "$status"
if [ $status -eq 0 ]
then
# Remove the pidfile before the script echoes anything to stdout and is killed by bigd
rm -f $pidfile
echo "up"
fi
# 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.
Thank you
01-Nov-2020 13:29
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