Advertisement
metalx1000

Check if Script is already running

Dec 29th, 2024 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.35 KB | None | 0 0
  1. # Check if Script is already running
  2. pidof -o %PPID -x "$0" >/dev/null && echo "ERROR: Script $0 already running" && exit 1
  3.  
  4. # if the above doesn't work(if the version of pidof works differently)
  5. # then try this  (I needed this for script on android with Termux)
  6. pgrep -f "$0"| grep -v $$ > /dev/null && echo "ERROR: Script $0 already running" && exit 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement