0

I have the following crontab setup.

30 * * * 1-5 /home/ubuntu/script_abc.sh 

script_abc.sh has permission -rwxr-xr-x and the following content.

#!/bin/sh
source ~/my_app/venv/bin/activate
export APP_KEY=abkajdfljdasfljdalfk
cd ~/my_app
python ~/my_app/scripts/scan.py 

It seems crontab never run my script. Any idea?

asked Aug 6, 2019 at 19:05
4
  • crontab can run script as different user, with different permitions, and different system's variables. It is good to use full path - not ~/ Commented Aug 6, 2019 at 19:08
  • It seems the error is coming I can't activate the Python virtual env Commented Aug 6, 2019 at 19:08
  • and it is is good to use full path for programs - /usr/bin/python. You can get full path for program using which - ie. which python Commented Aug 6, 2019 at 19:12
  • Remember thast your .profile and .bashrc are skipped by crontab, PATH modifications and other settings are ignored. Try source /home/ubuntu/.profile inside your script or your crontab command. Commented Aug 6, 2019 at 20:35

2 Answers 2

1

crontab dosn't set PATH an cannot find the binarys. Add PATH at the top of your script, or with an export at top of crontab.

# for example
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
answered Aug 7, 2019 at 4:45
Sign up to request clarification or add additional context in comments.

Comments

1

Is it a local user's crontab or are you making changes in /etc/cron.d/ if it is the latter, you need to mention the user name like I am doing in the below example:

30 14 * * * root <script>

if it is the former, you can.

  1. Look at the syslog. You will see what is happening when the cron daemon tried to call your script.

  2. Make sure you have absolute path in all your scripts.

answered Aug 6, 2019 at 19:15

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.