The question I personally have is will it be possible to design the cron job according to this �wish list':
1)Every time cron starts (I mean files are found and processing begins) - email send to a user or to a group of users.
2)The job is divided into 2 separate parts, 2nd jobs starts only after first one has completed
a) All xxx, yyy and zzz(file names)
b) aaa and bbb files
3)At the end of an each job an email is sent to me &co, notifying that job completed.
4) If job fails for whatever reason an email is send to me &co with description (as useful as possible) with a problem.
Please help me...me new to scripting....'
thanks in advance...
Yes, It is possible to achieve your requirements.
1)Every time cron starts (I mean files are found and processing begins) - email send to a user or to a group of users.
Ans. try this command
ls filename >output
if [ -s output ]; then
echo "THE FILE FOUND" | mailx -s "The file found" userid@domainname.com
else
echo "THE FILE NOT FOUND" |mailx -s "The file not found" userid@domainname.com
fi
2)The job is divided into 2 separate parts, 2nd jobs starts only after first one has completed
a) All xxx, yyy and zzz(file names)
b) aaa and bbb files
ANS: you could have a wrapper script where in you could call other scripts something like this
in the wrapper script:
. /xxx
if [ $? -ne 0 ]; then
echo "ERROR xxx failed to execute"
exit 1
fi
# below code will run only when xxx is complete
. /aaa
if [ $? -ne 0 ]; then
echo "ERROR xxx failed to execute"
exit 1
fi
Note: Make sure you put an exit 0 at the end of the script and exit 1 where ever you exit with error.
3)At the end of an each job an email is sent to me &co, notifying that job completed.
Ans: continuing with the pervious code you could add and else statement in the if condition something like this
. /xxx
if [ $? -ne 0 ]; then
echo "ERROR xxx failed to execute"
exit 1
else
echo "JOB xxx EXECUTED SUCCESSFULLY" | mailx -s "JOB aaa executed successfully" email@email.com
fi
# below code will run only when xxx is complete
. /aaa
if [ $? -ne 0 ]; then
echo "ERROR aaa failed to execute"
exit 1
else
echo "JOB aaa EXECUTED SUCCESSFULLY" | mailx -s "JOB aaa executed successfully" email@email.com
fi
4) If job fails for whatever reason an email is send to me &co with description (as useful as possible) with a problem.
ANS: in the previous code you could add the mail command in the if condition itself
. /xxx
if [ $? -ne 0 ]; then
echo "ERROR xxx failed to execute"
echo "JOB xxx FAILED" |mailx -s "JOB aaa FAILED" email@email.com
exit 1
else
echo "JOB xxx EXECUTED SUCCESSFULLY" |mailx -s "JOB aaa executed successfully" email@email.com
fi
# below code will run only when xxx is complete
. /aaa
if [ $? -ne 0 ]; then
echo "ERROR xxx failed to execute"
echo "aaa JOB FAILED" |mailx -s "JOB aaa FAILED" email@email.com
exit 1
else
echo "JOB aaa EXECUTED SUCCESSFULLY" | mailx -s "JOB aaa executed successfully" email@email.com
fi
Hey Ahmed...Thanks for ur immediate reply...i really appreciate it...Thanks a ton...i will try this and will get back to you if i come up with some issues...