1

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
Pete
  • 271
  • 1
  • 4
  • 19
  • Don't have enough rep to comment, but does that script have execute permissions for that user and group? I.e. did you create the file as mike and you trying to run the script from pete's cron? – codehitman Mar 14 '14 at 15:05
  • error says `not found`, this is not permission related – alexus Mar 14 '14 at 15:07
  • Yes. Its in my user's home dir and my user's crontab. I can manually run it, and the weird thing is that it executes *most* of the time. – Pete Mar 14 '14 at 15:22
  • Okay: suggestion: replace the path to "~/diskreport.sh" . See if that changes anything. – codehitman Mar 14 '14 at 15:23

3 Answers3

1

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.

Pete
  • 271
  • 1
  • 4
  • 19
0

all shell scripts should start w/ following line #!/bin/bash (replace bash w/ whichever shell you're using

alexus
  • 13,112
  • 32
  • 117
  • 174
  • Sure, like I said, I've corrected that. But the error wasn't preventing it from executing (it was just running under sh, which is fine). – Pete Mar 14 '14 at 15:25
0

Do:

 whereis sh

get the shortest path, e.g. /bin/sh and change your crontab job to:

0   1   *   *   *    /bin/sh    /home/username/diskreport.sh
Manolo
  • 552
  • 2
  • 8
  • 23
  • interestingly `whereis` returned /bin/sh.distrib which is a symlink to dash, and sh's man gz in share. `which` sh returns /bin/sh. – Pete Mar 14 '14 at 17:50