Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 07-23-2009, 09:31 AM   #1
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!

Old 07-23-2009, 10:06 AM   #2
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
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,396

Rep: Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395
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
LQ Newbie
Registered: Jul 2009
Location: Canada
Distribution: Mint, Fedora, Ubuntu Server
Posts: 27

Original Poster
Rep: Reputation: 2

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!


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 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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:59 AM.

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