0

First of all I am not very familiar with cron... Under .../cron/crontabs I have a file (which is called root, not sure whether it needs to be the same as the user?) with one job:

* * * * * sleep 0; wget -0 /var/cache/file.txt 'IP-ADDRESS'
* * * * * sleep 10; wget -0 /var/cache/file.txt 'IP-ADDRESS'
* * * * * sleep 20; wget -0 /var/cache/file.txt 'IP-ADDRESS'
...

And this works: it downloads the contents of the IP address and saves into my file every 10 seconds. There are other three commands with sleep 30, 40 and 50.


Now I want to add another job that executes a python script every 10 seconds.

I tried to create a new file under .../cron/crontabs, which I called job2 but nothing happened.

  • can I just create as many cron scripts as I want? Do I need to start them somehow?

Since this did not work, I tried to add my second job to the existing root file, which now reads:

* * * * * sleep 0; wget -0 /var/cache/file.txt 'IP-ADDRESS'
* * * * * /home/user/Documents/pythonscript
* * * * * sleep 10; wget -0 /var/cache/file.txt 'IP-ADDRESS'
* * * * * /home/user/Documents/pythonscript
* * * * * sleep 20; wget -0 /var/cache/file.txt 'IP-ADDRESS'
* * * * * /home/user/Documents/pythonscript
...

where pythonscript is an executable, and I made sure that the cron folder has permissions to the python script path...

  • This still does not work. How do I make cron execture a python script?
1

Yes, you can have only one crontab per user, and its filename is the username.

Also, the proper way to edit it is to run crontab -e -- it's entirely possible that the cron daemon doesn't notice you've changed the file directly. Just call crontab -enow, it will open your editor with the crontab, and it will reload the config after you save and exit, and your other jobs should start running.

  • When I type <code>crontab -e</code> I just see a number...? – SuperCiocia Jan 31 '18 at 16:09
  • I actually found the answer... I just add to first change the directory to the one where my script lives, then exectute it... – SuperCiocia Jan 31 '18 at 16:37
  • By the way do you know what exactly <cron> crontab -e </code> is supposed to return? I have two machines, and on one it gives a number (random?) and on the other it makes me see and modify the crontab file with commands. – SuperCiocia Jan 31 '18 at 16:38
  • @SuperCiocia: it will open your preferred editor (as given in the environment variable EDITOR or VISUAL) with the crontab file (I think technically a temporary copy of it which it copies back afterwards) and reload the crontab when the editor exists. – Ulrich Schwarz Jan 31 '18 at 16:47
  • So why do I get a number out? – SuperCiocia Jan 31 '18 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.