0

I want to run a script in every X hours, that's why I wrote a BASH (named as mybash.sh) what is calling this script like this :

#!/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/usr/src/Python-2.7.13 python /usr/src/Python-2.7.13/test1.py

This bash file is in my /usr/src/Python-2.7.13 , and my test1.py too. If I am running the sh mybash.sh it is running! I did chmod a+x mybash too.

Into the crontab-e I wrote that:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/usr/src/Python-2.7.13 
* * * * * /usr/src/Python-2.7.13/mybash.sh 2>&1

If I am calling the crontab-l I am seeing these lines there.

But my script not running..What am I missed?

EDIT1 - cat /etc/crontab

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
8
  • Why did you wrapped python script into bash script ? Commented Oct 9, 2017 at 6:50
  • Because I read that, it is the usual process to run a .py file with the cron. Commented Oct 9, 2017 at 6:52
  • what does the script do? also, why are you not using the python interpreter that comes with Debian? Commented Oct 9, 2017 at 10:06
  • the script is web-scraping (open some websites), how can I use it? Commented Oct 9, 2017 at 10:14
  • does the script require a GUI? (open a browser?). what do you have in /var/log/cron.log? what does the user under which the cron-scrip is being executed get in the ${MAIL} file? (when replying, please use "@umläute" so i get notified) Commented Oct 9, 2017 at 12:29

1 Answer 1

0

You could simple invoke python in the crontab

* * * * * [path/to/py/executable] [path/to/py/script]

Remember to specify the complete path to executable due to restricted variables in cron environment.

Sign up to request clarification or add additional context in comments.

12 Comments

So i have to write maybe this one? : * * * * * /usr/src/Python-2.7.13/mybash.sh /usr/src/Python-2.7.13/test.py ?
nope, i mean, for example * * * * * /usr/bin/python /usr/src/Python-2.7.13/test.py
no output neither mail log? Are u sure u found the right python path? If u put /usr/bin/python (or whateaver) in a shell, it spawns Python interpreter?
i am sure, because my python program is start with #!/usr/bin/python and #!/bin/sh . So i don't know why it cant start
so, i cant help you there 'cause it should be good... just a stupid question, have you inserted the blank like at the end of crontab? maybe post the result of cat /etc/crontab here, if it's not too long
|

Your Answer

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.