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.
Thank you in advance for your help.
I wrote a simple shell script to append text to a file. At the end of the file i used the tail command to view the the last lines of appended text form the file. When I execute the file from the command line with a ./ it seems to work fine. However, when i set the command up to run as a cronjob (crontab -e) the job runs,
but the only output I get is to mail(and to the file). How do I get the output to display to stdout?
By default if cron generates output on stdout or stderr the result will be mailed to the user owning the cron job. This is because cron jobs are often run when nobody is logged in and there is nowhere for output to be displayed.
You could try something like the following in your cron job:
gilead, Vixie cron (ie cron written by Paul Vixie), and probably also some other flavors of cron, support adding
at the top of the crontab file to send the stdout/stderr of cron jobs to the specified mail address, rather than to the owner of the cron job (default).
MAILTO="" makes sure that the output doesn't get mailed at all (stdout/stderr are then simply disregarded).
kazador, it's rather hard (if not impossible) to make cron's stdout/stderr appear let's say on your terminal window (ie your shell's stdout). Imagine what would happen if the cron job runs while you aren't logged in or don't have an open terminal window. Furthermore, how can cron know to which terminal window it's supposed to send the stdout/stderr to? Cron itself runs independently from anything you're running. It just runs the jobs you defined for it, as if they were run by you (so, under your user) and sends the stdout/stderr via e-mail to you.
Alternatively, you could catch the output of your "tail" command in a file and then do a "cat" of that file in your terminal window to see what "tail" was outputting. If you don't like the e-mails.
Hi timmeke, thanks for that. I didn't know what distribution that kazador was using, so I left my response as general as possible. For example, Dillon's cron does not support MAILTO in crontabs. At least, not in the man pages for crontab or crond, and the variations that I tried all continue to email to the owner of the cron job.
Piping the output to mail works regardless of the distro used. As an alternative, the cron docs suggest that if the job is being run as a special user (e.g. UUCP) that a mail alias be set up so that the mail is diverted to a regular user. Aliases didn't sound applicable to the original question so I didn't bother mentioning them previously.