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?
EDIT
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.
EDIT 2
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:
THIS DIRECTORY HAS BEEN UNMOUNTED TO PROTECT YOUR DATA.
From the graphical desktop, click on:
"Access Your Private Data"
or
From the command line, run:
ecryptfs-mount-private
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...
root
relevant? Is it the same script that runs sometimes or are some scripts found and other not?