Linux – crontab cannot find script

cronecryptfslinux

I have a cron job that runs under my user once per night. I installed it using crontab -e and a by adding the line:

0   1   *   *   *     /home/username/diskreport.sh

The crontab is set up so that it emails me the result. Seemingly randomly I get an email from Cron Daemon stating the script is not found (opposed to the output of diskreport.sh).

/bin/sh: 1: /home/username/diskreport.sh: not found

I did have an error at the start of the script which I've corrected, but it wasn't preventing the script from running. It runs fine under both sh and bash:

#~/bin/bash

Best Answer

It turns out this was related to ecryptfs and having a encrypted home directory. The "seemingly random" behavior was triggered by having an active SSH session with my user logged in. While logged in cron was able to read my home directory because it was mounted and decrypted. While logged out the script is unavailable. Thanks for all the helpful suggestions.