I want to monitoring cron jobs using shell script. But if I use variable contain exit code of last command I have "0" always. I think it's because I run this script after cron job and "exit code" takes value "0" (start script) How can I ignore start of the script and use "exit code" variable of previous cron job?
$ ls foo ; echo $? ls: cannot access foo: No such file or directory 2
$ ls foo ls: cannot access foo: No such file or directory $ sh test.sh 0
My test.sh:
#!/bin/bash notify() { EXIT_CODE=$? echo ${EXIT_CODE} } notify