Bash Check If Script Is Running
Zur Navigation springen
Zur Suche springen
1 #!/usr/bin/env bash
2 #Usage: ./checkscript.sh scriptname
3 if [ $# = 0 ]; then
4 echo "Error. No script name given!"
5 exit 1
6 fi
7 #check if script is running
8 if pidof -sx $1 >/dev/null 2>&1
9 then
10 #when running do nothing but echo pid
11 echo "Script process id: "$(pidof -sx $1) 2>&1
12 else
13 #if not running change dir
14 #and start script if exists
15 cd ~/sensor/Python/Raspberry_Pi
16 if ls $1
17 then
18 ./$1 &
19 else
20 echo "Script not found! Check name."
21 fi
22 #start script
23 fi