Question

Lets say I have a crontab job that runs every minute, and the job involves mailing the output of a shell script to some email address. I know for sure that this job takes more than a minute to complete. How does the operating system handle this? I check my syslog, it shows me that the job is running, but no indication of an email being sent. I am relatively new to Linux, so bear with me please :]

Was it helpful?

Solution

By creating the following script:

#!/bin/bash

file=/tmp/test$RANDOM

touch "$file"
sleep 600
rm "$file"

And running it every minute in my crontab.

guido@solid:~$ crontab -l
*   *   *   *   *   /home/guido/cmd.sh

I can see that there are many instances of cmd.sh running by:

guido@solid:~$ ls /tmp/test*
/tmp/test7822   /tmp/test12278  /tmp/test16118  /tmp/test25642
/tmp/test11429  /tmp/test15958  /tmp/test18172  /tmp/test26104
guido@solid:~$ ps -e |grep cmd.sh
26005 ?        00:00:00 cmd.sh
26454 ?        00:00:00 cmd.sh
26999 ?        00:00:00 cmd.sh
27450 ?        00:00:00 cmd.sh
27895 ?        00:00:00 cmd.sh
28667 ?        00:00:00 cmd.sh
29220 ?        00:00:00 cmd.sh
29727 ?        00:00:00 cmd.sh
30232 ?        00:00:00 cmd.sh

This means, your mailing job is being ran multiple times, which may lead to some problems. Either up the interval until you're sure that there's no overlap, or change the job to take a lock so there are no issues.

As to why there's no indication on your mail being sent, I can't help without more info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top