Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
In the linux world you can redirect your stdout, stderr or even stdin in most cases to wherever you would like. The link has some examples, talks about the differences and should be enough to get you there. If you have any specific questions please let me know.
I read the tutorial that Kustom42 linked, and I am not sure if I need something more then stdout. As I understand it will create a file and it will contain what you would see on the screen if you type the some command and execute it.
In terminal when I type some command and execute it, if there is a error, it print it in terminal.
Why actually I need stderr?
It comes down to how much info you want, 99% of the time I only redirect standard output and forget about stderr. It's really something you have to decide based upon what you are going to be logging/redirecting and if you want to capture any stderr.
stderr would only be a problem with executing the script from BASH's side. So if the script was not executable it would generate a stderr saying that, however, if the script itself errors out and generates an error that it was programmed to that would actually be stdout as it is the output of the script.
> # creates a new file
>> # as above or appends if file already exists
If you only want the last N iterations it gets more fiddly.
I'd go with appending the date/time to the filename as above and get the logrotate tool to auto remove the older copies.
Re post #6; I'd recommend tracking stdout & stderr; you can't get those error msgs back, and the next run may not exhibit the same issue. You may also need(!) to know before the next run.
Your choice though ...
Cron automatically sends you a mail message IF there is any output to stderr or stdout.
If you want a detailed log of the commands/responses you need a "set -v" (verbose) mode for the shell. It will then output each command line as read. If you also want to know exactly what expansions the shell makes during execution, use "set -x". If you want both use "set -vx"
You can also redirect stderr/stdout if you don't want a mail message (redirecting removes any output, thus cron has nothing to send...)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.