LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 09:31 AM   #1
blingham
LQ Newbie
 
Registered: Jul 2009
Location: Canada
Distribution: Mint, Fedora, Ubuntu Server
Posts: 28

Rep: Reputation: 3
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, 10: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 10:09 AM.
 
Old 07-23-2009, 06:32 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 07:59 AM   #4
blingham
LQ Newbie
 
Registered: Jul 2009
Location: Canada
Distribution: Mint, Fedora, Ubuntu Server
Posts: 28

Original Poster
Rep: Reputation: 3
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



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 08:56 PM
Scan log file for errors huskerharry Linux - Newbie 7 10-20-2006 01:43 AM
write errors to log file, instead of /dev/null c_r2005 Linux - General 2 07-30-2005 08:34 AM
How do I log on-screen errors to file skunkburner Linux - General 9 06-02-2005 02:51 AM
error: stat of /var/log/ppp/connect-errors failed: No such file or directory Niceman2005 Linux - Newbie 0 01-20-2005 12:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:32 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
Open Source Consulting | Domain Registration