Hi ,
I have a script which everyone have access but I need that the script should be ran by one user at a time. The second user who is trying to execute the script should get a message stating that the user is already executing the script. Is there any way to achieve this.?
It is just hint.
Cons - If you use ctrl c in middle of script then next time you can't run the script even if script is not running.
Solution - Get PID at the start of the script and then use that to check if the script is still running or not.( this i left for your exercise)
try something this..
if [[ ! -f test_script_check ]]
then
echo "test2.sh" > test_script_check
echo "script is running"
sleep 100
rm test_script_check
else
echo "script is already running"
fi
Also you could write the current user into the check file, and if someone else tries to run it, the error message could print who is currently running it.