• Uncategorized

About linux : crontab-nohup-trigger-itself-twice

Question Detail

This is the crontab:

0 10 * * * (file_path).sh > /data/log/(file_name).log 2>&1

Every day at 10am, this is the result when I check on this shell script using ps -ef | grep 'file_name'

report 1234 5678 0 10:00 ?    00:00:00 /bin/sh -c (file_path).sh > /data/log/(file_name).log 2>&1
report 8270 1234 0 10:00 ?    00:00:00 /bin/sh -c (file_path).sh > /data/log/(file_name).log 2>&1
report 9290 8270 0 10:00 ?    00:00:00 sqlplus -s @/(file_path).sql > /data/log/(file_name).sql.log 2>&1

Because of this, this crontab takes a very long time because it is running the shell script twice before going to the sql script.

When checking at crontab -e, there’s only one line executing this. So there is no duplicate cronjobs running at the same time. Based on this one line, it is executing the shell script twice.

Anyone know why this keeps happening?

Question Answer

Also note the using ( ) interpreted by the shell as creation of subshell.

Suggesting to remove ( ) from filename.

From your ps output:

report 1234 5678 0 10:00 ?    00:00:00 /bin/sh -c (file_path).sh > /data/log/(file_name).log 2>&1
report 8270 1234 0 10:00 ?    00:00:00 /bin/sh -c (file_path).sh > /data/log/(file_name).log 2>&1
report 9290 8270 0 10:00 ?    00:00:00 sqlplus -s @/(file_path).sql > /data/log/(file_name).sql.log 2>&1

It is possible to trace the process forking/spawning tree:

1234 spawns 8270 spawns 9290.

There could be some parallelism mechanism in your (file_path).sh

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.