I have a script running every 5 mins with two exits in a condition clause.
#!/bin/bash
date=$(date +%Y)
if [ $date -eq '2014' ]
then
echo "Current year is $date"
exit 0
else
echo "Current year is not $date"
exit 2
fi
How could I specify to only write a log when exit 2? Could this be possible in crontab?
5 * * * * /home/user/script.sh >> script.log 2>> script.err
I have understood that " >> script.log " writes all the return of the script and " 2 >> script.err " writes only if the script didn't run correct. So I don't know if there's a chance to write only where exit 2 down the script.
#!/bin/bash
. And replace{
with(
and}
with)
in second line. – Arkadiusz Drabczyk Jun 20 at 15:25