-1

i'm trying to schedule my pythohn script into Centos 7 with cron. On my script at start i have added this:

#!/usr/local/bin/python

and this is my cron file that i have create into folder that contain python file

*/5 * * * * /usr/local/bin/python /home/Documents/SCRAPE_PYTHON/SCRAPE.py &>> /home/Desktop/log.txt

i have try to run the script into terminal by chmod +x and works fine. But whit this configuration when in terminal i set crontab .cron the job doesn't work. The log file set into cron file are not write and script not run. The script could be write some data into db and the db is always empty. Any help??? Thanks

APPGIS
  • 353
  • 1
  • 10
  • 20
  • you are using command `crontab -e` for adding or updating cron jobs ? – Renjith Thankachan Mar 23 '17 at 16:22
  • no i have used vim to create cron file. the correct workflow to creare a schedule python with cron? – APPGIS Mar 23 '17 at 16:31
  • How about specifying the interpreter itself on the crontab line. I guess it's because the environment variables that we mortal users take for granted (like $PATH) are minimally set up when running from cron. – eftshift0 Mar 23 '17 at 16:34
  • i'm not very expert on linux can you hel me with step to do – APPGIS Mar 23 '17 at 16:40

1 Answers1

3

Type crontab -e in the shell, this will open the cron editor. Here copy paste the entire command.

*/5 * * * * /usr/local/bin/python /home/Documents/SCRAPE_PYTHON/SCRAPE.py &>> /home/Desktop/log.txt

Now press Esc key then type colon :wq! and press Enter key. This will install your cron. Your cron should run every 5 minutes.

Your standard output and error will be appended to /home/Desktop/log.txt.

nomad
  • 973
  • 2
  • 9
  • 22
  • can you explain the syntax here? is `&>> /path/to/file.txt` the syntax for associating log files? also, to execute the script i want to install a cronjob for i usually have to use the command `scrapy crawl mycrawler`, so how do i do that or? – oldboy Jul 02 '18 at 00:25