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 all,
I'm trying to start a script through crond. The record in crontab is: 30 16 * * * /home/alex/razhodilim.pl 1>/dev/null
The script razhodilim.pl works perfectly if I start it manually. But cron fails to start it.
What could be the reason?
E. g. ensure that cron is running as the same user who wrote the script. Also, check that the script is readable and executable as regards permissions, by the user cron is running as.
You can also try running the script via the root user's crontab, just to debug - don't run it like that permanently - if it DOES work, it means you have some form of permissions or owership problem with the script you need to run.
Also, it seems like you're running a perl script? I see no reference to the perl binary. Remember that you might have an environment when you run the script from your terminal, but that cron will not have that same environment and path settings, e. g. it might not be able to automatically find perl to execute the script, you may need to call perl explicitly in your crontab.
The commonest reason for this type of problem is that cron sets up a restricted environment compared with the logon environment; in particular the PATH environment variable is set in a basic way. Your script can set the PATH it needs (which is robust good practice anyway).
Cron "executes" anything that it is supposed to run. The file must therefore be "executable," and furthermore it must be executable by the right user.
The documentation in man cron really is pretty good, once you've also read the various other manpages that are referenced in it. Also, if cron is unable to perform a request for any reason, it will log an error-message in a file that will (probably) be found somewhere within /var/log/messages. A command such as grep -riw cron, issued in that directory by a duly authorized user, will probably be very helpful.
Also, if cron has an issue, it generally emails the cron user (or possibly root).
You could also change
Code:
1>/dev/null
to
Code:
1>/tmp/mylog 2>&1
to see if its trying to tell you something.
As per post#4, cron has a restricted environment; ensure you set/source any vars you need, with the absolute/full path to all files referenced (or start by setting the right env).
@rylan76: you don't need to specify perl in the cmd, just set it at the top as the first line of code, similar to other scripting style langs eg
Hi,
Thank you all for the instructions. The file razhodilim.pl is executable, it runs without problems if started manually.
The crond is started by root.
There were no mails.
I tried to redirect the output to a file as Chris suggested but the log file is empty.
In the /var/log/cron file there is a record : USER root pid 6598 /home/alex/razhodilim.pl 1>/home/alex/error 2>&1
I also tried setting PATH variable with the paths I have in the login environment - nothing changed.
Two ideas: 1) start crond at a higher logging level and 2) try scheduling a very simple bash, ksh or sh script that does nothing except echo running > /home/alex/error
Probably irrelevant as the script runs from the command line but what is its first line, probably a shebang line?
Hi catkin,
I restarted cron with logging level 12, wrote the script test.sh which echoes in /home/alex/error and scheduled it in crontab. The cron executed it. There was no log in /var/log - cron stopped logging at all.
The first line of razhodilim.pl is #!/usr/bin/perl
The script has to open a file in /home/alex and it wasn't able to find it if run through cron. I put the full path in the script and that solved the problem.
Thank you all!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.