Home > Enterprise >  In Linux, how to run Django custom management using crontab?
In Linux, how to run Django custom management using crontab?

Time:11-16

I have generated a bash script that activates virtaulenv and runs my custom management command in Django. I want to run the bash script every day at midnight.

Bash Script :

cd ~
cd path_to_virtualenv/
source virtualenv_name/bin/activate
cd path_to_project/
python manage.py custom_command
deactivate

When I run this script using . or source it runs perfectly. I have configured crontab to run this bash script (For testing, I have set execution time per minute). But I am not getting desired output.

crontab -e

*/1 * * * * source /path_to_bash_script/bash_script_filename

CodePudding user response:

  1. Add shebang to your shell script (i.e: #!/bin/bash, ...)
  2. Remove source from crontab
  3. add an extension to your script file.

CodePudding user response:

I changed the script as :

#!/bin/bash
source /path_to_virutalenv/bin/activate
python /path_to_project/manage.py custom_command

In crontab :

*/1 * * * * bash /path_to_bash_script/script.sh
  • Related