Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Crontab "Can't open perl script", " No such file or directory"

by Anonymous Monk
on Oct 09, 2014 at 13:19 UTC ( [id://1103297]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a cron task set to run daily at 7am. The crontab file has a few perl scripts. I can always manually execute the perl script and it will run without a problem. But it seems like every few days (2-4) the cron task will fail. Oddly once the cron fails when I log into the server and change the time of the script to run later that day, it will successfully execute. But if I leave it at that new time, it will stop running a few days later. I have tried to run the cron task with both my user name & root and get the same result. Maybe it only runs successfully when my user name is logged into the server, otherwise there is no access to my user directory?
Current OS: Ubuntu 14.04.1 LTS Perl: (v5.18.2) crontab -e 0 7 * * 0-6 /usr/bin/perl /home/myuser/scripts/perl/flash.pl 0 7 * * 0-6 /usr/bin/perl /home/myuser/scripts/perl/flash2.pl Cron email report (the previous day I had a successful script output): Can't open perl script "/home/myuser/scripts/perl/flash.pl": No such f +ile or directory" ... Can't open perl script "/home/myuser/scripts/perl/flash2.pl": No such +file or directory" Manually running script: :~/scripts/perl$ pwd /home/myuser/scripts/perl :~/scripts/perl$ ls -al total 256 drwxrwxr-x 4 myuser myuser 4096 Oct 7 11:19 . drwxrwxr-x 8 myuser myuser 4096 Aug 1 10:12 .. -rwxr-xr-x 1 myuser myuser 5962 Jul 10 15:16 flash.pl -rwxr-xr-x 1 myuser myuser 5534 Jul 10 15:19 flash2.pl Manual execution: :~/scripts/perl$ /usr/bin/perl /home/myuser/scripts/perl/flash.pl running for: 2014-10-08 Number of rows affected: 8 Syslog w/cron which could not find directory: Oct 9 07:00:01 CRON[5525]: (myuser) CMD (/usr/bin/perl /home/myuser/s +cripts/perl/ALPT_mme_flash.pl) Oct 9 07:00:01 CRON[5527]: (myuser) CMD (/usr/bin/perl /home/myuser/s +cripts/perl/ALPT_volte_flash.pl) Syslog w/cron which worked yesterday: Oct 8 07:00:01 CRON[4556]: (myuser) CMD (/usr/bin/perl /home/myuser/s +cripts/perl/flash.pl) Oct 8 07:00:01 CRON[4559]: (myuser) CMD (/usr/bin/perl /home/myuser/s +cripts/perl/flash2.pl)

Replies are listed 'Best First'.
Re: Crontab "Can't open perl script", " No such file or directory"
by McA (Priest) on Oct 09, 2014 at 14:41 UTC

    Hi,

    as cron is throwing away most environment variables I do want to have a script run exactly like I would do it on the console. I use two ways:

    You want to collect all cron jobs in one crontab of root but want to run them with a certain uid:

    * * * * * su - user -c '/usr/bin/perl /home/myuser/scripts/perl/flash. +pl'

    or you run it in the crontab of the user and force an environment as if you have logged in:

    * * * * * bash -l -c 'usr/bin/perl /home/myuser/scripts/perl/flash.pl'

    Probably this would also trigger the mounting of your home directory if this is the reason for your problem.

    Regards
    McA

      Given the reply earlier about single hard drive on laptop, I would think that the directory (or, parent) would be already mounted and thus removes automount or similar. (The explicit question was still not answered.)

      Could it be possible that that a bad "shebang" line (not shown), if present, would be causing the problem even though the program is started explicitly via /usr/bin/perl per OP?

        That would be a very odd situation indeed considering he said it does run sometimes. If there was an issue determining what binary would interpret the file, it shouldn't ever run.

      I just put in, bash -l -c, and will take a look tomorrow.
Re: Crontab "Can't open perl script", " No such file or directory"
by Anonymous Monk on Oct 09, 2014 at 13:38 UTC

    Is /home/myuser/scripts/perl mounted without user intervention (automount, perhaps)? To rephrase, is /home/myuser/... on local file system that is mounted during boot?

      Along the same lines, are you using encrypted home directories?
        The server is running on a laptop, with 1 hard drive, which is not encrypted.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1103297]
Approved by karlgoethebier
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-29 10:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found