Is there any none python solution to avoid this problem and make sure
the script runs only if not already running?
Yes, in bash, you can check whether the script is running or not by the script's filename(used in the command to run the script) from within a bash shell script-file like so:
#!/bin/bash
if [ $(/bin/pgrep -f "script_file_name.sh") ]; then # Change "script_file_name.sh" to your actual script file name.
echo "script running"
# Command when the script is runnung
else
echo "script not running"
# Command when the script is not running
fi
or in a one line(that you can, directly, use in e.g. a crontab
line) like so:
[ $(/bin/pgrep -f "script_file_name.sh") ] && echo "script running" || echo "script not running"
socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
– Rinzwind Jul 21 '22 at 06:19