I am executing a daily script in ubuntu server via Cron which runs a java file. I want to it to be included in if/else block such that if the java file is executed successfully its should send an echo message “successfull” and if it fails it should send an echo message “failed”.
Here are the existing lines for the script updateGroupScores.sh
java -classpath "/home/ubuntu/live/build/WEB-INF/lib/*:/var/lib/tomcat7/lib/*:/home/ubuntu/live/build/WEB-INF/classes/" com.generalsentiment.update.UpdateGroupScores > /var/gs/livecron/crongroupsentimentscores.log
i want to modify them something like –
if (java file runs successfull)
then
echo "cron job successfull"
else
then
echo "cron job failed"
—
Thanks
If you can rely on the exit status of the Java command, then simply write:
Note that the output will be mailed to you (on some systems at least), or lost to
/dev/null. The variables make everything fit better on the SO screen; I’d probably use them in a regular script too, though it would be a borderline decision.If you can’t rely on the exit status, you’ll have to do something else to decide whether it succeeded or not, but the general principle is very much the same regardless.