Reputation: 91
I want a python webscraping program to be run everyday at a certain time. For that i am using this command in the cron in ubuntu
28 22 * * * root /home/ahmed/Desktop python hello.py
It just doesnt work. there must be something wrong with it. can anyone help me please?
Upvotes: 2
Views: 3414
Reputation: 46533
Try adding #!/usr/bin/python
(called shebang line) to the top of your Python script and then
28 22 * * * root /home/ahmed/Desktop/hello.py
You have to make your script executable like this (run this as a separate command):
sudo chmod +x /home/ahmed/Desktop/hello.py
From the Shebang page on Wikipedia:
Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest of the script's initial line as an interpreter directive; the specified interpreter program is run instead, passing to it as an argument the path that was initially used when attempting to run the script.[8] For example, if a script is named with the path "path/to/script", and it starts with the following line: #!/bin/sh then the program loader is instructed to run the program "/bin/sh" instead (usually this is the Bourne shell or a compatible shell), passing "path/to/script" as the first argument.
If you don't want to change anything this will work as well:
28 22 * * * root python /home/ahmed/Desktop/hello.py
Upvotes: 2
Reputation: 189387
/home/ahmed/Desktop
is (most probably!) not a valid command name. You want
28 22 * * * root python hello.py
or possibly
28 22 * * * root python /home/ahmed/Desktop/hello.py
depending somewhat on why you put that folder name there.
The syntax of a regular user's crontab
is different. I can imagine no legitimate reason to run a scaping program as root
. To run it from your own crontab
you should use
28 22 * * * python /home/ahmed/Desktop/hello.py
(again possibly without the path name, or with the path somewhere else in the command line).
Upvotes: 2