Notifications
Clear all
Jan 26, 2021 7:02 pm
How to create and manage lock file in Bash script to avoid multi execution
1 Reply
Feb 02, 2021 4:31 pm
here is a sample of bash script and managing Lock file kindly have a look
#!/bin/bash
# Check is Lock File exists, if not create it and set trap on exit
if { set -C; 2>/dev/null >~/manlocktest.lock; }; then
trap "rm -f ~/manlocktest.lock" EXIT
else
echo "Lock file exists… exiting"
exit
fi
# Do Something, Main script work here…
echo "I am a script and I am doing something… anything…"
sleep 30