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.
There are other caveats besides the path that can trip up users when running scripts from cron. Basically when a script runs via cron it isn't connected to a terminal/display so it can't display messages.
There are other caveats besides the path that can trip up users when running scripts from cron. Basically when a script runs via cron it isn't connected to a terminal/display so it can't display messages.
You might want to add your SHELL and PATH variables to the script itself.
Is the script executable by the user running the cron job you show?
Yes, Script is executable.
Below is updated script after your comments. But still no echo output on the console.
#! /bin/sh
SHELL=/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/bin
crond has no console, it will not be able to echo anything (and jobs initiated by crond will inherit its state, so they will have no console too).
Awesome info. I ran crond in foreground and bingo. I see the echo messages.
crond: USER root pid 1879 cmd /home/IM/test.sh
Hello there
crond[1877]: crond: USER root pid 1882 cmd /home/IM/test.sh
Hello there
It isn't true you can't do echo from a cron job. What you can do is send the output of cron scripts to a log file.
* * * * * /home/IM/test.sh >>/tmp/test.log 2>&1
The echo you did would show up in that log (along with any errors should they occur). You could also set separate logging for individual commands within the script itself and also set stderr (file descriptor 2) to a separate log.
I notice you mention X11 as well though you're not actually using it here. For things that require an X display you'd have a similar problem because you're not on a display but you can use a tool called xvfb to run X sessions in the background.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.