linux - Schedule cron entries to run script only when not already running -


i have 1 shell script in crontab executing jar file. jar file moving files 1 server server. in peak hours taking more 10 minutes(more crontab entries).

how can make sure cron job not execute process until last 1 not completed ?

an easy way have cron start bashfile checks if such process exist.

cron:

 */10 * * * * /path/to/bashscript.sh 

(make sure has correct user , executable)

the pgrep command looks process given name, , returns processid when such process found.

#!/bin/bash # bashscript.sh      pid=$(pgrep -n "yourjarfile")   # check if jarfile running if $pid > /dev/null            #log syslog      logger  $pid "already running. not restarting."  else     # start jar file      /usr/bin/java -jar /path/to/yourjarfile.jar fi 

--edit--

inspired f. hauri's answer (which works fine btw), came shorter version :

 */10 * * * *  pgrep -n "yourjarfile." || /usr/bin/java -jar /path/to/yourjarfile.jar 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -