LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-23-2009, 10:31 AM   #1
blingham
LQ Newbie
 
Registered: Jul 2009
Location: Canada
Distribution: Mint, Fedora, Ubuntu Server
Posts: 27

Rep: Reputation: 2
Question Sending Errors to Log File: Best Practice?


Hi everyone, I'm trying my hand at shell scripting, and have successfully created a backup script that creates tar files of my web, mysql and VMWare data directories. I know, simple stuff...

So I then added the ability to verify the exit codes of each command, and print a status message based on Success or Fail using the echo command. Again, not rocket science, but this is useless considering I set this up in cron, and would never see those messages.

My question is this, I want to redirect, and append the success messages to a log file, however I'm not sure which log file. What is the best, or most-common practice for this type of activity? Do I create a new log file called Backups and just >> the status messages to it, or do I append to /var/log/messages or /var/log/syslog?

I'm guessing the difference is that you could easily tail a dedicated log file to see the last few instances, whereas I would have to cat /var/log/messages | grep "failed" to get any failures...?

Any opinions on this subject would be greatly appreciated!

Thanks,
Jay
 
Old 07-23-2009, 11:06 AM   #2
nuwen52
Member
 
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208

Rep: Reputation: 46
If you want to go the syslog route, check the "logger" program. You can specify the facility and log level in command line arguments, and let syslog handle where it should go (and configure syslog accordingly if needed).

A dedicated log file isn't a bad idea, but there are two instances that can get annoying: Remote logging (if you need that) also needs to be done manually (through e-mail or whatever). Maintaining the logs can get annoying also (trimming them of old entries, etc.). Syslog is already (in most distros) set up to handle these problems.

But, if you don't need to worry about these things, simply redirecting the output should do the trick.

Last edited by nuwen52; 07-23-2009 at 11:09 AM.
 
Old 07-23-2009, 07:32 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
If you really want, you can create your logs in the usual area eg /var/log and set a custom logrotate script to keep them under control. Just copy an existing logrotate script, should be some there already, and modify.
 
Old 07-24-2009, 08:59 AM   #4
blingham
LQ Newbie
 
Registered: Jul 2009
Location: Canada
Distribution: Mint, Fedora, Ubuntu Server
Posts: 27

Original Poster
Rep: Reputation: 2
Smile

Thanks to you both for your answers!

I have tried out nuwen52's suggestion, of using logger to log success/failure messages directly to /var/log/syslog.

I then wrote a quick login script to show me any failure messages when I log in.

I've tested both manually, and today just shortly after noon will be the first cron run.

Thanks again!
Jay
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
FX5600 Geforce - FC9 - black screen, no (EE) errors in /var/log/Xorg.0.log?? boyd98 Linux - Hardware 1 06-17-2008 09:56 PM
Scan log file for errors huskerharry Linux - Newbie 7 10-20-2006 02:43 AM
write errors to log file, instead of /dev/null c_r2005 Linux - General 2 07-30-2005 09:34 AM
How do I log on-screen errors to file skunkburner Linux - General 9 06-02-2005 03:51 AM
error: stat of /var/log/ppp/connect-errors failed: No such file or directory Niceman2005 Linux - Newbie 0 01-20-2005 01:29 AM


All times are GMT -5. The time now is 05:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration