linux - Running python program after it is terminated via crontab -
i have python webscraping program needs scrapped continuously after program terminated. technique follows
crontab -e (settings)
* * * * * /home/ahmed/desktop/run.sh
run.sh
tmp_file=/tmp/i_am_running [ -f $tmp_file ] && exit touch $tmp_file /usr/bin/python /home/ahmed/desktop/python.py rm $tmp_file
the bash code must have problem or may command in crontab wrong. program not running. please guide
after mark suggestions modified script this
#!/bin/bash path=$path:/bin:/usr/bin date +'%h:%m:%s started' >> /home/ahmed/desktop/log.txt tmp_file=/tmp/i_am_running [ -f $tmp_file ] && exit touch $tmp_file date +'%h:%m:%s starting python' >> /home/ahmed/desktop/log.txt /usr/bin/python /home/ahmed/desktop/python.py rm $tmp_file date +'%h:%m:%s ended' >> /home/ahmed/desktop/log.txt
the cron command using * * * * * /home/ahmed/desktop/run.sh
the log file created this
15:21:01 started 15:21:02 starting python 15:22:02 started 15:23:01 started 15:24:01 started 15:24:30 ended 15:25:01 started 15:25:01 starting python 15:26:01 started 15:27:18 started 15:28:01 started 15:29:01 started 15:30:01 started 15:31:01 started 15:31:16 ended 15:32:01 started 15:32:01 starting python 15:33:01 started 15:34:01 started
it seems program restarted before ended. log file should have starting program, started, ended, starting program, started, ended , on.
can guide me please?
have made script executable?
chmod +x /home/ahmed/desktop/run.sh
put proper shebang , path in script starts this:
#!/bin/bash path=$path:/bin:/usr/bin
try script on own command line
/home/ahmed/desktop/run.sh
if doesn't work, change shebang line add -xv
@ end
#!/bin/bash -xv
check see if /tmp/i_am_running exists
check cron log
grep cron /var/log/syslog
consider changing script can see when started and/or if ran python:
#!/bin/bash path=$path:/bin:/usr/bin date +'%h:%m:%s started' >> /home/ahmed/desktop/log.txt tmp_file=/tmp/i_am_running [ -f $tmp_file ] && exit touch $tmp_file date +'%h:%m:%s starting python' >> /home/ahmed/desktop/log.txt /usr/bin/python /home/ahmed/desktop/python.py rm $tmp_file date +'%h:%m:%s ended' >> /home/ahmed/desktop/log.txt
by way, not sure how running once @ 18:01 constitutes "continuous scraping"?
Comments
Post a Comment