[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!
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.