check program myscript with path /root/check_db.sh
if status != 0 then alert
So, I want to send alert when status not equals to some value(say 0).
So, I want if to generate exit status of not zero whereas else to generate exit status of 0. So, I don't get alert when else is executed whereas, I get alert when if gets executed.
I would also want to wait 10 times till I get the differences > 600 before sending alert.
You wrote in your title returning different exit code...
An exit code is different than an alert, an alert is a message you put, that you check in the output... and exit code is a stop of execution with a code value for you to know where in your script it stopped
To be clear: the child process returns an un-named status value with exit.
Its parent process must collect that value immediately, with a command like:
status="${?}"
and you would check it like:
if (( status != 0 )); then send-alert.sh; fi
The reason for collecting the status immediately is that almost all Bash commands set a new status. Even an echo of the value as debug, or the first of multiple tests, will change it.
$
$ bash ## Open a child shell.
<my subshell> $ exit 27 ## Exit with status
exit
$ echo "${?}"
27
$ echo "${?}"
0
$
The second echo reports the success of the first echo, not the status of the previous shell as might be expected.
I didn't want to ask a new thread. I wrote this script. But the problem is it queries database every 1 monit cycle. Since the target Alerts don;t go at night as no transactions occur at night, it'll keep alerting and spamming emails.
Is there a clever way to check if a system is functioning correctly or not?
The server is a java web server consisting of wrapper.log. I tried to telnet its ports but I suspect the ports of this server change at restart(Not sure).
Any guidance? I need to find if a module in linux server is up or down.
First I need to define the state UP. I am not sure how do I do it.