Forum

How to create and m...
 
Notifications
Clear all

How to create and manage lock file in Bash script


mani
Posts: 7
 mani
Topic starter
(@mani)
Active Member
Joined: 4 years ago

How to create and manage lock file in Bash script to avoid multi execution

Topic Tags
1 Reply
cssudhakar
Posts: 3
(@cssudhakar)
New Member
Joined: 4 years ago

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

 

Reply

Leave a reply

Author Name

Author Email

Title *

Preview 0 Revisions Saved
Share: