1

I have a file which I loaded into crontab with the following jobs, and crontab -l reports the following:

# runs daily at 2:00 am and 2:05 am
30 12 * * * /usr/bin/wget -q -O temp.txt http://<host-url>/cronjob/script1.php 35 12 * * * /usr/bin/wget -q -O temp.txt http://<host-url>/cronjob/script2.php

Cleaner version of Output Above

# runs daily at 2:00 am and 2:05 am

30 12 * * * /usr/bin/wget -q -O temp.txt http://<host-url>/cronjob/script1.php 
35 12 * * * /usr/bin/wget -q -O temp.txt http://<host-url>/cronjob/script2.php

I followed the rules as per this site:

How to Set-up a Cron Job

I initially had an issue with having both jobs display in the crontab list. I resolved that issue by having all jobs set up on one line as detailed in the section of:

Dealing with Error Messages from Crontab

Once I had both jobs listed correctly, I tested to verify that they executed correctly. At 12:31 I noted that both scripts executed, for script1 and script2 both modify different tables in a mysql database.

Why did this occur? How can I schedule it so that script2 executes at it's own scheduled time?

I realize this is not such a huge issue but I am curious to know.

Thank you for your assistance.

2
  • "If comments and code disagree, both may be wrong"... The comment in your crontab says 2:00 am and 2:05 am. Either fix or remove that comment. That said, I've never seen cron run things at the wrong time. Check syslogs to see if cron logs what and when it executes. Also you say "resolved that issue by having all jobs set up on one line"; are you sure the crontab is modified as you show?
    – wurtel
    Commented Sep 15, 2014 at 14:40
  • The comments do not affect it, I just left it that way so that I could recall what time I wanted the jobs to effectively complete. I have a solution which I am about to post.
    – mcv
    Commented Sep 15, 2014 at 14:52

1 Answer 1

1

I opened the cron job to be edited using:

crontab -e

And made edits using Nano.

I added a new line character between jobs and this fixed the problem.

So the file initially created was done on a Windows machine which was FTP to the server. I checked out the file and it was created in Notepad++ without an extension, also tried with an extension of .TXT. The EOL character was set to UNIX.

No matter the scenario, when loading the file, both jobs executed on the first scheduled time. After I modified cron jobs using the edit above. The cron jobs executed at the scheduled time (aka 5 minutes apart).

1
  • Interesting! So it was a problem with the file itself. +1 for discovering it.
    – fedorqui
    Commented Sep 15, 2014 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .