If i have the following entries in my cron table:
00 03 * * * /java_prog1.sh
00 5 * * * /java_prog2.sh
The first job usually takes around 30 m
The creation of directories is atomic, so you could add this in both scripts:
lock_dir=/tmp/name_of_lock_directory
if ! mkdir "$lock_dir"; then
echo "Cannot run $0: lock directory $lock_dir exists" >&2
exit 1
fi
cleanup () { rm -r "$lock_dir"; }
trap cleanup EXIT
# if you want, you can add the running pid to a file in the lock directory
echo $$ > "$lock_dir/pid"