Bash Check If Script Is Running

Aus AirSpaceWatch & More
Version vom 17. Januar 2021, 16:32 Uhr von Raz0rsedge (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „<syntaxhighlight lang="bash" line='none'> #!/usr/bin/env bash #Usage: ./checkscript.sh scriptname if [ $# = 0 ]; then echo "Error. No script name given!" exi…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
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