[SOLVED] Sending Errors to Log File: Best Practice?
Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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!
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.
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.