4

I created an entry in crontab to execute a job at midnight as e.g user A.

In the morning, I found there were no results of the script. Checking the /var/cron/log, I found that during that hour (same time) only a script user root was executed.

Questions: a) Can we set multiple jobs in cron to execute the same time.
b) If no? Does this mean user root cron has precedence over any other user to execute the cron job?

here is what they look like.

root$ crontab -l
05 00 10 * * /opt/sdf/sbin/somescriptA.sh> /dev/null 2>&1 #Test

userA$ crontab -l
05 00 10 * * /opt/sdf/sbin/somescriptB.sh> /dev/null 2>&1 #Test
3
  • Does the root user script reboot the machine, prematurely ending the job? Jun 10, 2009 at 14:10
  • Not all cron providers are created equally. Which cron package are you using?
    – Dan Carley
    Jun 10, 2009 at 14:22
  • using Solaris 10 platform.
    – Syed
    Jun 11, 2009 at 9:55

10 Answers 10

5

Cron can run many scripts at the same time. In fact, in Debian there are entire directories of cron scripts (ie. /etc/cron.daily /etc/cron.hourly) that execute at the same time.

If the script executes properly at a different time, why don't you try changing the time of the root cron job to determine whether the problem is with the actual timing, or a conflict between the scripts.

I also agree with turning off the redirect to /dev/null until you have everything working correctly.

3
  • 2
    Or, if you don't have the machine setup such that cron can send mail to a useful place when it sees output from a job, change the redirects to point to files instead like ">> /root/temp.cron.job.log 2>&1" or such. Just make sure you turn it off when you are done (or add the file to your logrotation setup) otherwise the file will grow until it fills the partition. Jun 10, 2009 at 15:46
  • /etc/cron.daily /etc/cron.hourly don't all execute at the same time. They execute in asciibetical order, one after another.
    – Cian
    Jul 5, 2009 at 13:31
  • Though it is too old question, but I have to ask one thing. Let, I have a CRON action at every 30 second. But one CRON takes about 1 minute to finish. Is there any problem with this? Can same CRON task can runs twice or more times parallelly? Jul 19, 2018 at 21:09
4

That crontab you posted is set up to only run at 00:05 the 10th every month, is this what you wanted?

Please check that your script in /opt has executeable permissions, and that it's prorperly calling up sh. You can try this by simply running the script in the console (by using its full path, dont put "sh" in front of the command)

Try to check the directory /var/spool/cron/ for your username, the cron file should be there (somewhere - I don't have access to a system right now).

1
  • accurate and correct - +1
    – GNUix
    Jun 11, 2009 at 6:39
3

I would take the /dev/null redirect off of the job and have cron email you the output of the file. It could be the script has a problem (maybe assuming an environment variable that doesn't exist when running through cron).

1
  • there is no entry in /var/cron/log for userA at all, seems like it didnt execute at all at that time, if I change the timing to something different it will execute with no issue.
    – Syed
    Jun 10, 2009 at 13:58
2

Cron jobs can run at the same time. Your problem is something else. .. or .. the script is running as root. Maybe what you're trying to run has its own method of preventing more than one instance.

1
  • there was no entry in /var/cron/log for my script run as e.g user A
    – ssharizal
    Jun 10, 2009 at 13:38
1

I would suspect that there is some interaction between the two scripts like a lock file or an open file.

1
  • thanks Dennis, the root script is doing some cleaup tidy work while the other is dumping data although the folder are not the same though, but the base folder is the same /tmp, this would be something that I should look into.
    – Syed
    Jun 10, 2009 at 14:07
1

I have never had a problem with multiple cron jobs running at the same time. Just tested on my Slackware system, works fine, but it may vary according to distro.

That said, it's usually a good idea to stagger the minutes of your crontab entries anyway so they're not all running at the same time (just to prevent unnecessary load on the system and potential interaction problems).

I double Milner's suggestion of checking the output of the cron jobs rather than redirect it to null. At least until you debug why the jobs themselves aren't working.

0

Users should be able to run cron jobs simultaneously with no problem. Have you confirmed that user A is permitted to use cron (try checking /etc/cron.allow and /etc/cron.deny).


3
  • If a user isn't permitted to run cron, then they should not be permitted to edit and maintain a crontab.
    – Milner
    Jun 10, 2009 at 13:53
  • You can also check whether the cron job runs successfully by setting it to execute "in 5 minutes" and observing your machine for evidence of success.
    – Mike Mazur
    Jun 10, 2009 at 13:53
  • hi ktower, yes, the user is permitted to execute the cron. I fail to mentioned that the script execute nicely when I change the time for user A script in its cron.
    – Syed
    Jun 10, 2009 at 13:57
0

Did you use crontab -e to edit the crontab? It may be that crontab has not noticed your change, you must use this command to edit/install new crontabs.

1
  • yes, I used crontab -e to edit them. here is what they look like. root$ crontab -l 05 00 10 * * /opt/sdf/sbin/somescriptA.sh> /dev/null 2>&1 #Test userA$crontab -l 05 00 10 * * /opt/sdf/sbin/somescriptB.sh> /dev/null 2>&1 #Test
    – ssharizal
    Jun 10, 2009 at 13:36
0

I have never heard of cron silently disabling cron jobs because others were scheduled for the same time. That should work, so I guess your problem is elsewhere.

BTW, this sounds like something for serverfault.com.

0
0

I had a similar issue and I was suspecting that running two different scripts at the same time from my user crontab could be the problem. I realised that the issue was actually that the permissions on the top level directory of the second script were "drwx------" and cron couldn't access it to run it. After modifying the permissions on that directory, it was executed smoothly.

You must log in to answer this question.

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