I've wrote a script for fetch real uptime and display in monit
. But I think it displays just exit error status. My uptime script is:
#!/bin/sh
uptime=`uptime | awk -F " " '{print $3}'`
echo $uptime
exit $uptime
When I run it in terminal result is true
For example:
# uptime
08:39:01 up 421 days, 19:54, 1 user, load average: 0.06, 0.10, 0.06
# ./up_time.sh
421
Script works well. But when monit starts to run this script by up_time.conf file;
Program Status Last started Exit value
days_up Status ok Thu, 01 Aug 2013 08:41:08 165
I saw on the browser. I guess that Exit value
is the bash exit error code. I cant get why other script are works fine but this one does not do his job
Speaking of which, monit
up_time.conf
file is like this:
check program days_up with path "/etc/monit/scripts/up_time.sh"
if status < 1 then alert
The exit value of a commands are an unsigned 8 bit integer (aka a 1 byte). This means the exit value must be between 0 and 255. Your script seems to be trying to set an exit value of 412 which simply isn't valid as an exit code. The extra bits will get ignored, and so the actual value that gets returned is 156.
Here is some output using bash's
$?
to demonstrate. The `$? variable is stores the exit value of the previous command.Why
exit $uptime
? Shouldn't it be justexit 0
, meaning your shell script did finish OK?