- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- flagging script failures
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2002 04:30 AM
тАО11-05-2002 04:30 AM
I have a cron job that executes daily and I'd like an email sent to a user if this job fails. Other than checking the return code in the cron log, what's the easiest way to do this?
There are about half a dozen commands in the script so I could get the value of $? and check each line has worked but there nust be a better way.
Thanks,
Gary.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2002 04:38 AM
тАО11-05-2002 04:38 AM
Re: flagging script failures
The return code in the cron log is simply the code returned by the script. Depending on how that's written it may be the code returned from the last command run.
If you post the cron script, I'd be able to give you some more information.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2002 04:47 AM
тАО11-05-2002 04:47 AM
Re: flagging script failures
it's quite a simple script that extracts lines from a number of data files and concatenates them into another file.
I could check each command individually but I was wondering if there was a way to globally trap errors. Something like an "on error then goto" function.
I also wondered if there was a way to flag the fact that the cron job has failed. I could create another job that scans the cron log but I was hoping there was a simpler way.
Regards,
Gary.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2002 05:09 AM
тАО11-05-2002 05:09 AM
Re: flagging script failures
As with most other things in UNIX though, there are many ways that you can code though. For instance, you can do...
if [[ ${?} -eq 0 ]];
then
if
then
if [[ ${?} -ne 0 ]];
then
if !
then
etc...
The || construct can be useful with an error handling function, for example:-
function failit {
commands here to send you a mail etc. Arguments can be supplied to the function to give additional information about the failure.
exit
}
command1 || failit "command1 failed"
command2 || failit "command2 failed"
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2002 05:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2002 05:18 AM
тАО11-05-2002 05:18 AM
Re: flagging script failures
Put the entire main portion inside a function; at each major step, increment a position counter variable and export it. When you reach an error, perform a 'return' or 'break'.
Outside the function, test the value of the position counter; if it is not the final code (1 more than the variable for the last major step), display an error.
POSIX Shell programming has restrictive features, but some of them can be useful if you think a little laterally.
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2002 05:19 AM
тАО11-05-2002 05:19 AM
Re: flagging script failures
look at "man crontab":
-----------------
WARNINGS
Be sure to redirect the standard output and standard error from
commands. If this is not done, any generated standard output or
standard error is mailed to the user.
---------------
So cron sends mail by default if you don't use redirection:
* * * * * command 1>/tmp/command.out
means that standard-out is written to file and standard-error sends a mail to the user of the cron
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2002 06:21 AM
тАО11-05-2002 06:21 AM
Re: flagging script failures
I think I'll go with Robin's suggestion, putting "||" in crontab.
Regards,
Gary.
p.s. Ian, I was thinking DCL not VB!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2002 07:39 AM
тАО11-05-2002 07:39 AM
Re: flagging script failures
Perhaps I come too late, but I just want to add that a 'on error' like functionnality really exists in Posix shell. I never used it because I don't find it 'clean' enough, but ...
trap "echo error in script; exit 1" ERR
manages a special trap to gives this message and exit 1 whenever a command returns a non zero exit code. See man sh-posix, trap command.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2002 10:00 AM
тАО11-05-2002 10:00 AM
Re: flagging script failures
00*** script 2> mail (etc....)
I've never tried this... i was wondering if this would work?