My crontab entry intermittently fails to find scripts in my user's home directory. The crontab entries run exactly on schedule as specified, and occasionally the script runs correctly, but mostly it only produces output like this:

/bin/sh: 1: /home/<user>/script/check_cgi.pl: not found

The crontab entry for this is:

5,35 * * * *    /home/<user>/scripts/check_cgi.pl >>/tmp/check_cgi.pl.out 2>&1

I have double-checked that the script exists, and that root can see the filesystem and that the command runs correctly if I sudo to root.

Does anyone have any suggestions as to why cron would frequently not be able to find a file and how to solve it?


This is root's crontab (edited by sudo crontab -e), hence the relevance of checking that root can see the script.

The permissions on the script are:

-rwxrwxr-x 1 <user> <user>  700 Apr 20 09:27 check_cgi.pl

and the directory permissions 775 or 755 too, so there is no problem with root having permissions to execute the script.

It seems that cron started to "find" the script after I added a new cron job to run "find /"; as if forcing cron to go through the entire directory tree allowed it to "find" the script again.

There are 4 scripts, which are all contained in the same directory. They run at various times (every 15 mins, every 30 mins, once per day) and they all have this problem at the same time. And then when the problem goes, they all work ok.


I have found the problem... By running each hour the cron job "ll -lR /home", I discovered that around 15.00 it started to incorrectly report the contents of the /home/ directory. Instead of the correct collection of directories (including the required scripts directory), it showed the completely different contents :

lrwxrwxrwx 1 <user> <user> 56 Jan 18 20:53 Access-Your-Private-Data.desktop -> /usr/share/ecryptfs-utils/ecryptfs-mount-private.desktop
lrwxrwxrwx 1 <user> <user> 52 Jan 18 20:53 README.txt -> /usr/share/ecryptfs-utils/ecryptfs-mount-private.txt

And when I view the /usr/share/ecryptfs-utils/ecryptfs-mount-private.txt file, it tells me:

From the graphical desktop, click on:
 "Access Your Private Data"
From the command line, run:

So that appears to be the answer. The home directory is set up as an encrypted filesystem and the operating system unmounts it in periods of low use "to protect your data".

I just need to work out how to disable this behaviour either permanently or when the cron jobs run. I guess the answer is within ecryptfs-mount-private...

  • Which user's crontab is this? Why is root relevant? Is it the same script that runs sometimes or are some scripts found and other not? – terdon Apr 24 '14 at 11:20

The ubuntu help describes this problem https://help.ubuntu.com/community/EncryptedHome

There are a few minor caveats that one must keep in mind about these encrypted configurations.
When you are not logged into your system, data in your home directory is not accessible in plain text. This, of course, is by design. This is what keeps an attacker from gaining access to your files. However, this means that:
1.    Your cronjobs may not have access to your Home Directory 

The solution is, I think, not to have encrypted home directories, or move the files to somewhere that root can see (like root's home directory).


It's weird the script runs well occasionally.

But, in my experience, most of the problems related crontab is a privilege.

crontab runs the script with it's own privilege, not root.

Therefore, how about "chmod 707" or "777" to your script and your user's folder??

  • chmod xx7 is almost always terrible advice, especially on a home directory. – guntbert May 18 '17 at 17:13

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.