- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- shell script for the cron job failure
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
Forums
Discussions
Discussions
Discussions
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
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
07-14-2003 01:51 AM
07-14-2003 01:51 AM
I am looking for a shell script which reads log file (/var/adm/cron/log) and it will e-mail the error message to the me, if there are any "rc" errors or the cron fails.
I want to schedule this script to run once a day and hence it should look for the crons which has run on the same day only.
Does anyone has a readymade script or give me some tips to get started.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 02:00 AM
07-14-2003 02:00 AM
Re: shell script for the cron job failure
Have a look at this thread :-
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xf0fc5dc05a7ad711abdc0090277a778c,00.html
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 06:14 AM
07-14-2003 06:14 AM
Re: shell script for the cron job failure
Add
cp /var/adm/cron/log /var/adm/cron/log.old
echo "" > /var/adm/cron/log
To the end of your job and then you only have cron since the last time your script ran
backup log.old later
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 06:58 AM
07-14-2003 06:58 AM
Re: shell script for the cron job failure
to make the script look only at the newer line in the log file, you can use the following:
1. initialise the file /tmp/croncheck:
echo 0>/tmp/croncheck
#!/usr/bin/ksh
j=`wc -l /var/adm/cron/log| awk '{print $1}'`
i=`cat /tmp/croncheck`
tail +$i /var/adm/cron/log >/tmp/tocheck
# run your error treatment job on /tmp/tocheck
echo $j >/tmp/croncheck
rm /tmp/tocheck
tail +$i will tail the /var/adm/cron/log file starting at line $i. This means that you get the last message from yersterday, which I think is a good idea.
If you truly want to start at the next line, you can use
tail +$(( $i + 1 )) /var/adm/cron/log >/tmp/tocheck
instead.
HTH,
FiX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 06:56 PM
07-14-2003 06:56 PM
Re: shell script for the cron job failure
Paula,
I didn't find any cron check script in the link given by you.
Steve,
Seems to be a good idea.
Fix,
# echo 0>/tmp/croncheck
# j=`wc -l /var/adm/cron/log| awk '{print $1}'`
# i=`cat /tmp/croncheck`
# tail +$i /var/adm/cron/log >/tmp/tocheck
tail: cannot open input
error: No such file or directory on file +
#
I am getting the error mentioned above.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 07:40 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 07:40 PM
07-14-2003 07:40 PM
Re: shell script for the cron job failure
The user who runs the cron jobs get detailed emails from root.You can always setup .forward in / to send the emails wherever you want to. The emails have alot of great info about the script and why it failed.
If you dont want the information for every cron script you can do it per job.You can also redirect the output and email your self standard error and output.
Use this on the to of the script
exec > /home/richard/file.log 2>@1
And this at the bottom.
cat /home/richard/file.log | sendmail you@whereever
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 10:58 PM
07-14-2003 10:58 PM
Re: shell script for the cron job failure
> Fix,
> # echo 0>/tmp/croncheck
> # j=`wc -l /var/adm/cron/log| awk '{print $1}'`
> # i=`cat /tmp/croncheck`
> # tail +$i /var/adm/cron/log >/tmp/tocheck
> tail: cannot open input
> error: No such file or directory on file +
> #
looks like $i is not set. Could you echo $i and see if it's actually got a value? When I run the commands, I have:
# echo 0 > /tmp/croncheck
# cat croncheck
0
# j=`wc -l /var/adm/cron/log| awk '{print $1}'`
# echo $j
56662
# i=`cat /tmp/croncheck`
# echo $i
0
# tail +$i /var/adm/cron/log >/tmp/tocheck
# wc -l /tmp/tocheck
56662 /tmp/tocheck
# echo $j >/tmp/croncheck
# cat croncheck
56662
I forgot to use the full path for tail in my script: it should be /usr/bin/tail for use in cron, of course.
Are you using the korn shell? The script is written for ksh, and may not work with other shells...
HTH,
FiX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2003 12:07 AM
07-15-2003 12:07 AM
Re: shell script for the cron job failure
as I know, everytime a cronjob failed the system creates a mail for the local root account.
Know I think you can configure sendmail on your system that this mails will be forwarded to your email account. You can do this very simple with the aliases file in /etc/mail/aliases.
put this in alaiases file.
root: sanjiiv@mydomain.com
Now you will get all emails from root also to your account.
Or do this.
root: "|
( from man page aliases:
.....
| command-line sendmail pipes the message as standard input to the specified command. If command-line contains blanks, it must be enclosed in quotation marks (").
For example,
msgs: "|/usr/bin/msgs -s"
......
)
Regards
Roland
Perhaps another way for solving your problem.