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.
I have a task setup to run on my cronjob where I need to read the output. What I need from the output is the starting character (let's say 'A') and the ending character (let's say 'Z'). A helps me understand my script started from the right place, and Z helps me understand my script finished at the right place.
So, it is important for me to run that cronjob, and see that my output is having proper A and Z.
I know that not sending the script to '> /dev/null' will try to mail using the MTA, which is not something I want to do. I also don't want to send it to /dev/null because I need to read the output.
When I run my script normally from the console (tty), I am able to see the start character (A) and end character (Z), but when I let the cronjob run, my script fails to read the start character and complains about 'no start characters'.
In an early part of your post, you seemingly wrote about using, for example, 'A' and 'Z' as output.
Later, you wrote about your script reading, for example, 'A' and 'Z'.
From that it seems unclear as to exactly what needs your script has. Even apart from that, it would probably help in general, to have more details.
I feel it can be helpful, when writing a script to run as a cron job, to use absolute file paths for all files. Any output you want to see that you don't want to be E-mailed to you, or appear in the system log files, you can write to specific disk files, rather than stdout or stderr.
1.Is your script kept in crontab?.
2.When you run your script from in terminal,are you redireting output to any diskfile / is it only on stdout?.
3.If your script is in crontab , where your output is expected is it in /var/log file system or in any file.
Thank you both for your replies. And apologies if my query isn't as clear, part of this is because the script is not written by me, I know what it is supposed to do and I need to fix it, and I believe I have enough information to know what is wrong, just need to know how to fix it.
@Rigor: When the script runs, the output is bunch of lines and strings, the starting character (in this example A) and the ending character (Z) are the part of output, from which my script needs to read to know if it ran successfully. Maybe what was confusing you is that how can the script read the output if it has finished running. The script calls sub-script, each open a process in CPU, run, and report back to the main script by their output. All outputs are prepared for the main script to know the result of sub-scripts.
Sending to log file is not an option for this script, it is just not written like that and I can not change it.
@Virk: Yes, it is stored in crontab. From terminal, only stdout, and I can see the A and the Z properly. And no, there is no output to any log files.
It is worth mentioning that this script works on Windows and Mac, this issue so far is only on Linux.
If this is something to which you have legitimate access, and is not a homework assignment, then even if the script has to perform some specific action, you should be able to make changes for monitoring purposes. The output for monitoring purposes could be on a different file descriptor, so that it would not interfere with the purpose of the script.
I still don't understand the problem. How many scripts are you talking about here? Which one(s) are you trying to put in the cron? Why can't you redirect the output to a log file or directly to your parsing program?
As far as I'm concerned, there are four kinds of programs
1) Ones that print output you care about to stdout/stderr
2) Ones that print output you don't care about to stdout/stderr
3) Ones that print output to a log file
4) Ones that don't have any output
#1 - just redirect the output to a log file of your choosing or pipe it to the input of some other program directly
#2 - just redirect the output to /dev/null
#3 - it's already taken care of for you
#4 - there is no output, so it doesn't matter