- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: cron check script
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
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
08-14-2003 04:56 PM
08-14-2003 04:56 PM
Here is a script which sends an alert to me if the cronjob fails for today.
It has been observed that it doesn't give the cron status from Dates 2 to 9 but it works fine for the other dates. What needs to be done to make it work for dates 2 to 9?
Also I would like this script to give the cron status of only yesterdays cron jobs. What changes needs to be done for this?
*************
#!/usr/bin/ksh
admin1=ss1@abc.com
admin2=ss2@abc.com
host_name=`hostname`
DAY=$(date "+%a %b %d")
grep "rc=" /var/adm/cron/log | awk '/'"$DAY"'/ {print $0}' > /tmp/cronerrors.log
ERROR=`cat /tmp/cronerrors.log | wc -l`
if [ $ERROR -gt 0 ]
then
elm -s "ALERT!: $host_name: Cronjob failed !!" $admin1 elm -s "ALERT!: $host_name: Cronjob failed !!" $admin2 else
echo "Cronjob has run successfully"
fi
*******************
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 05:16 PM
08-14-2003 05:16 PM
Re: cron check script
My guess is that if you look closely at the cron log all single digit days have a double space between the Month & Day, therefore awk is not matching anything for 1-9.
Example:
root 22368 c Sat Aug 2
root 13313 c Fri Aug 15
Not sure if it shows clearly here but there is a double space between "Aug" & "2".
You need to adjust the pattern match in awk to account for this. Hope that makes sense!
Cheers
Con
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 05:23 PM
08-14-2003 05:23 PM
Re: cron check script
Yes. It makes sense. But how to adjust it to incorporates for the dates from 2 to 9.
I have received the cron status for date 1 but I am not sure how and why.
What about the cron status for the yesterday only?
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 05:26 PM
08-14-2003 05:26 PM
SolutionI hope this script meets all your requirement. Why don't you try this.
#!/usr/bin/ksh
month=`date +%m`
day=`date +%d`
year=`date +%Y`
month=`expr $month + 0`
day=`expr $day - 1`
if [ $day -eq 0 ]; then
month=`expr $month - 1`
if [ $month -eq 0 ]; then
month=12
day=31
year=`expr $year - 1`
else
case $month in
1|3|5|7|8|10|12) day=31;;
4|6|9|11) day=30;;
2)
if [ `expr $year % 4` -eq 0 ]; then
if [ `expr $year % 400` -eq 0 ]; then
day=29
elif [ `expr $year % 100` -eq 0 ]; then
day=28
else
day=29
fi
else
day=28
fi
;;
esac
fi
fi
case $month in
1) mon=Jan;;
2) mon=Feb;;
3) mon=Mar;;
4) mon=Apr;;
5) mon=May;;
6) mon=Jun;;
7) mon=Jul;;
8) mon=Aug;;
9) mon=Sep;;
10) mon=Oct;;
11) mon=Nov;;
12) mon=Dec;;
esac
x=`expr length "$day"`
if
[ $x -eq 1 ]
then
Day="${mon} ${day}"
else
Day="${mon} ${day}"
fi
cat /var/adm/cron/log|awk '/'"$Day"'/ && /'"$year"'/ && /'"rc="'/{print $0}' >/tmp/cronerr.log
mailx -s " Alert: Cron status" you@yourdomain.com < /tmp/cronerr.log
------------
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 05:40 PM
08-14-2003 05:40 PM
Re: cron check script
Very crude method, I'm sure others have a better idea:
//
DAY_NO=$(date +%d)
if [ $DAY_NO -lt 10 ]
then
DAY=$(date "+%a %b %d") # double space after %b
else
DAY=$(date "+%a %b %d")
fi
grep "rc=" ........ etc etc
//
Note the double space on first DAY variable setting in the "if" statement.
Haven't tested it but may work.
Cheers
Con
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 07:36 PM
08-14-2003 07:36 PM
Re: cron check script
For DAY_NO less then 10 we get DAY as for
example:
# date "+%a %b %d"
Wed Aug 06
August 6 comes as 06 and as the /var/adm/cron/log doesn't has 06 pattern it ignores the croncheck of August 6.
How can I make the date to display as Wed Aug 6 and not as Wed Aug 06?
Here your double space option doesn't help.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 07:54 PM
08-14-2003 07:54 PM
Re: cron check script
Use %e instead of %d. It will give date output in character with leading space not like decimel.
So you need to execute DAY=$(date "+%a %b %e")to get proper output.
Cheers
Dip
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 07:55 PM
08-14-2003 07:55 PM
Re: cron check script
What about
DAY_NO=$(date +%d | sed 's/^0//')
Cheers
Con
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 07:58 PM
08-14-2003 07:58 PM
Re: cron check script
does not use the leading "0" on dates 1-9, but DOES use a leading space.
OR
date "+%a %b %d"|sed "s/\ 0/\ /g"
Maybe one of these will help.
Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 07:59 PM
08-14-2003 07:59 PM
Re: cron check script
Yes. %e has helped.
Can we modify this script and make it to check the cron jobs which has run yesterday only?
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 08:00 PM
08-14-2003 08:00 PM
Re: cron check script
Thought I might have an answer worth points, but 2 people type faster than me!!
8-O
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 08:20 PM
08-14-2003 08:20 PM
Re: cron check script
Yes you can.
In your script just add following lines.
OLDTZ=`echo $TZ`
export TZ=MET+24 # It would set one day before date.
.....................
Execute all the commands...
In last line.
export TZ=$OLDTZ
Cheers
Dip
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 09:35 PM
08-14-2003 09:35 PM
Re: cron check script
I think this is dangerous.
When we execute
OLDTZ=`echo $TZ`
export TZ=MET+24 # It would set one day before date.
The date changes to the previous date and hence till the completion of the script it remains the same.
During this gap all the transation in the system will be as of yesterday's date. Don't you feel so.
Pls. correct me if I am wrong or else let us find out some other solution.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 09:37 PM
08-14-2003 09:37 PM
Re: cron check script
I think this is dangerous.
When we execute
OLDTZ=`echo $TZ`
export TZ=MET+24 # It would set one day before date.
The date changes to the previous date and hence till the completion of the script it remains the same.
During this gap all the transation in the system will be as of yesterday's date. Don't you feel so.
Pls. correct me if I am wrong or else let us find out some other solution.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 09:44 PM
08-14-2003 09:44 PM
Re: cron check script
I think it is dangerous.
OLDTZ=`echo $TZ`
export TZ=MET+24 # It would set one day before date.
This will set the date one day before and all the transation till the script executes fully will be as of yesterday's date.
Correct me of I am wrong or else let us look for some other method..
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 09:46 PM
08-14-2003 09:46 PM
Re: cron check script
I think it is dangerous.
OLDTZ=`echo $TZ`
export TZ=MET+24 # It would set one day before date.
This will set the date one day before and all the transation till the script completes fully will be as of yesterday's date.
Correct me of I am wrong or else let us look for some other method..
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 09:46 PM
08-14-2003 09:46 PM
Re: cron check script
I think it is dangerous.
OLDTZ=`echo $TZ`
export TZ=MET+24 # It would set one day before date.
This will set the date one day before and all the transation till the script completes fully will be as of yesterday's date.
Correct me if I am wrong or else let us look for some other method..
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 09:50 PM
08-14-2003 09:50 PM
Re: cron check script
I think it is dangerous.
OLDTZ=`echo $TZ`
export TZ=MET+24 # It would set one day before date.
This will set the date one day before and all the transation till the script completes fully will be as of yesterday's date.
Correct me if I am wrong or else let us look for some other method..
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 10:13 PM
08-14-2003 10:13 PM
Re: cron check script
I also use this TZ variable manipulation in my scripts. It shouldn't cause any problems. Don't export the TZ variable. Just set TZ back 24hours, then run your "date" commands and set TZ back to today.
EG:
TZ=EST+13EDT # Sets it back 24hrs
Run date commnads
TZ=EST-10EDT #Sets it to back to today
Cheers
Con
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2003 11:55 PM
08-14-2003 11:55 PM
Re: cron check script
I have used the TZ variable as advised by you but the time doesn't goes 24 hrs back nor it comes back to the original time.
# echo $TZ
SST-8
# date
Fri Aug 15 15:51:18 SST 2003
# TZ=EST+13EDT
# date
Thu Aug 14 19:51:31 EDT 2003
# TZ=EST-10EDT
# date
Fri Aug 15 17:52:14 EST 2003
#
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2003 12:13 AM
08-15-2003 12:13 AM
Re: cron check script
Here is the final script which meets my requirement.
Thanks to all.
****************************
#!/usr/bin/ksh
admin1=ss1@abc.com
admin2=ss2@abc.com
host_name=`hostname`
TZ=MET+24
DAY=$(date "+%a %b %e")
grep "rc=" /var/adm/cron/log | awk '/'"$DAY"'/ {print $0}' > /tmp/cronerrors.log
ERROR=`cat /tmp/cronerrors.log | wc -l`
if [ $ERROR -gt 0 ]
then
elm -s "ALERT!: $host_name: Cronjob failed !!" $admin1 elm -s "ALERT!: $host_name: Cronjob failed !!" $admin2 else
echo "Cronjob has run successfully"
fi
TZ=SST-8
*************************************
Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2003 05:26 PM
08-28-2003 05:26 PM
Re: cron check script
I have scheduled the above script to run once at 7:00 am every morning.
It has been found that it gives the cron report for day before yesterday.
How can I make it to give me the report of yesterday only?
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2003 05:36 PM
08-28-2003 05:36 PM
Re: cron check script
I'd guess its a problem with your TZ definition.
I'm not sure why you use TZ=MET+24.
Assuming your current TimeZone is SST-8 then to go back 24hrs use TZ=SST+16.
Then set it back to current day with TZ=SST-8.
Cheers
Con