I'm trying to set up a cron job to delete a file, I'm using a plesk interface, the command being:

* * * * 1-7 rm /mypath/file_name_to_delete

This should be executing every minute, right? It doesn't seem to be working.

  • 1
    "doesn't seem to be working" is not good enough description. did the file get deleted? check the mail of the user who runs it , what does it say? – user31894 Feb 3 '10 at 6:05
  • It doesn't get removed. Not sure about the checking mail thing, I'm going through a Plesk interface, there's no option to enter a mail or user who is running - which would be me, but I don't get any mail. Could it be a permissions thing? Should I contact my ISP? My syntax is correct, yes? – magenta placenta Feb 3 '10 at 6:11

Some observations:

  1. The fifth column of a crontab entry has a range of 0 (Sunday) to 6 (Saturday), not 1-7.
  2. Environment settings in a cron job are pretty sparse and tasks will often behave differently than they would in your interactive shell. It's a long shot, but make sure that the rm command is in the $PATH variable.
  3. Debugging cron jobs is tricky. Sometimes output from a job that isn't redirected to a file is mailed to you. Sometimes it isn't. Exercise more control over the output of your jobs:

    * * * * * my_cron_job >> /home/me/cron_job.log 2 >> /home/me/cron_job.err
  4. Try something simple to make sure cron is working and working the way you expect it to. Something like:

    * * * * * /usr/bin/date >> /home/me/cron.test 2>&1

    will test the basic functionality. You can make it more complicated from there.

  • Some good points here. I can't vouch for them all, but worth an upvote. – pavium Feb 3 '10 at 10:25

mobrule's answers are a good troubleshooting guide.

Additional hints:

  • If you don't get any mail, the system is probably not completely configured: All cron implementations (that I know of) will mail output (stdout & stderr) to the user who created the crontab (some also support a variable MAILTO to set that user). Problems usually occur if local mail delivery isn't correctly configured fot the user. If you use cron, always make sure local mail delivery is set up. Most Linux distros will do that automatically is you install their default mail server, which will dump mail into /var/spool/mail/, or forward it to the address given in the file .forward in the users' $HOME. This should be fixed if you're using cron, otherwise error messages will get discarded.
  • If you can only use Plesk, some of the settings mentioned above may not be accessible to you (though they should have been set by the hosting provider). In that case redirecting stdout & stderr to a file is a good workaround, as in mobrule's answer.

The rm filename command requires'yes' or 'no' confirmation. Therefore the command can't be executed without confirmation.

There is an 'rm -f filename' command for deleting files without confirmation.

  • I've never seen an implementation of rm that asks for confirmation by default. – Blacklight Shining Oct 22 '12 at 7:42

Your Answer

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