I want to use cron to hourly run a python program in Linux(ubuntu). I wrote a script called script.sh
cd Dropbox/NetworkProject/AMT_Crawler/
scrapy crawl AmtCrawler --set FEED_URI=data.json --set FEED_FORMAT=json
Then I used
crontab -e
and add a line like this
*/30 * * * * sh Dropbox/NetworkProject/AMT_Crawler/script.sh 2>&1 >> /Dropbox/NetworkProject/AMT_Crawler/output.log
After this, I run
sudo /etc/init.d/cron start
in terminal. It said
Rather than invoking init scripts through /etc/init.d, use the
service(8) utility, e.g. service cron start Since the script you are
attempting to invoke has been converted to an Upstart job, you may
also use the start(8) utility, e.g. start cron
So I run this
service cron start
Then there was an error:
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.196" (uid=1000 pid=12574 comm="start cron ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
Now I'm stuck with this problem asking for some help.
Best Answer
cron(8)
is always running. You do not need to start or restart it when you make changes to yourcrontab(5)
file usingcrontab -e
:(The last sentence is the reason why it is always recommended to use the
crontab(1)
program when modifying your owncrontab(5)
file.)