I'm running a script which is meant to process a few utilities in order to recover some data. This script is situated in a directory where the users can place their file that needs to be recovered. Since many users can have access to this directory and run the script, I want to have a condition that checks if the script is already running. If yes, then echo a "try again later" message; otherwise, run as usual.
I did some research on here and figured this to be a working code for my functionality as described above.
#!/bin/bash me="$(basename "$0")"; running=$(ps h -C "$me" | grep -wv $$ | wc -l); [[ $running > 1 ]] && exit;
I would like to implement this functionality and the code above in a Solaris SunOS 5.8. I understand that ps functions differently in Unix and Linux.