- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Error log and cron job
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
тАО01-18-2002 10:12 AM
тАО01-18-2002 10:12 AM
Error log and cron job
i have cron job that runs every minute.
* * * * * /script/m2o.sh >> /log/m2o.log 2>/log/m2o_err.log
it generates a empty error log every min.. but i want to generate log only if there is any error.
To be more specific. /script/m2o.sh is a very simple script. It can't produce any error but based on a specific condition it does call another script (probably twice a day) which may produce some errors. i want to log those errors.
please help me to resolve this problem.
Thanks
Vivek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2002 10:17 AM
тАО01-18-2002 10:17 AM
Re: Error log and cron job
i.e.
script1...
/usr/local/bin/script2 >> /log/script2.out 2>/log/script2_error.out
I think this is what you want.
GL,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2002 10:28 AM
тАО01-18-2002 10:28 AM
Re: Error log and cron job
Even if i applied your chnages, it is still creating a empty error log in case if there were no errors.
i want to create log if and only if there were some errors.
Hope you can help.
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2002 10:33 AM
тАО01-18-2002 10:33 AM
Re: Error log and cron job
ex.
if ( $? -ne 0 ) ; then
cat {your text here} >> error.log
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2002 10:41 AM
тАО01-18-2002 10:41 AM
Re: Error log and cron job
so you want to say that i have to generate error myself in script through code and then redirect them to a file. i can't catch the errors generated by script it self.
Waiting for reply.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2002 10:47 AM
тАО01-18-2002 10:47 AM
Re: Error log and cron job
When redirecting output to a log watch the redirect that you use:-
> will create a fresh log file each time
>> will append to a log file.
Your problem could be that you are creating a fresh log file each time.
So for the 2nd script the redirect of >> should be used so that on the next run the error data is not overwritten.
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2002 10:50 AM
тАО01-18-2002 10:50 AM
Re: Error log and cron job
I need to create a fresh error log evry time script runs but i need to create error log if and only if there were some errors.
Any Help ?
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2002 11:53 AM
тАО01-18-2002 11:53 AM
Re: Error log and cron job
( -f /path/errorlog ) -if error log file exists
( $?ERRORVARIABLE ) -if error variable exists
Another way might be to simply redirect your errout during the command inside the script.
{command} 2> errorlog
This will only send messages to the log in an error state.
Good Luck.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2002 01:38 PM
тАО01-18-2002 01:38 PM
Re: Error log and cron job
You could also take and either have a second script or append to the first one a check, after the log is created, where if the logfile is empty, then delete, and if it has an entry, append to your permanent log. Something like:
if [ test -s "logfile" ]
then
rm logfile
else
cat logfile >> permlogfile
this way it will always so the checking and delete the empty file.
Mark