[Answered ]-Crontab Jobs didn't execute shell script

0👍

Finally after pulling out my hair for several days, I found the working solution.

  1. I login to server using putty (SSH)
  2. Type commmand: crontab -e
  3. You will see the list of crontab jobs
  4. Add my job directly, I typed:

    0 3 * * * cp -pRu /home/path/to/my/project/file_dir /home/path/to/my/backup/dir

This will only copy new file/dir based on timestamps in file_dir to backup_dir everyday at 3 am

  1. After finished type, press ESC, then CTRL+x, it will ask you want to save, just type Y then hit ENTER to save the file.
  2. Check all the crontab job by type: crontab -l
  3. That’s it! Cheers man!

Hopefully, it helps someone who got similar problem 😀

PS: thanks to Igor and zsquare as well.

1👍

The cronjobs you schedule in your settings are not actually added to the crontab until you run python manage.py crontab add.

RTD

1👍

See the format of django crontab:

#format 1
required: cron timing (in usual format: http://en.wikipedia.org/wiki/Cron#Format)
required: the python module path to the method
optional: a job specific suffix (f.e. to redirect out/err to a file, default: '')

#format 2
required: cron timing (in usual format: http://en.wikipedia.org/wiki/Cron#Format)
required: the python module path to the method
optional: list of positional arguments for the method (default: [])
optional: dict of keyword arguments for the method (default: {})
optional: a job specific suffix (f.e. to redirect out/err to a file, default: '')

In both cases you need to use python methods, not just commands from the shell.
You are not allowed to write something like ‘cd …; ./command’; you should wrap this line into python module in your code.

More on it:

Leave a comment