Search code examples
ubuntucroncd

Why does my cron job sometimes fail on cd with "not a directory"?


I created a daily cron job on an unattended Ubuntu workstation:

0 3 * * * cd /home/spertus/src-mirror/blockly; svn up; git add -A; git commit -m "Automatic commit `date`"; git push

About half the time, it works. The other half of the time, I am emailed an error message that starts with the following line:

/bin/sh: line 0: cd: /home/spertus/src-mirror/blockly: Not a directory
Skipped '.'

Anyone know why cd would fail?


Solution

  • The most likely explanation is that your home directory is automounted, which means that /home/spertus isn't going to exist if you haven't accessed it recently.

    As you say in a comment, you should either move the directory somewhere else or find out how to force it to be mounted.

    It's possible that just accessing your home directory before executing the command:

    ls /home/spertus >/dev/null 2>&1; cd /home/spertus/src-mirror/blockly; ...
    

    would be sufficient, but I don't know enough about automounting to be sure.