background:
The device side of the project needs to run the jar package program to connect the socket with the server and send data. Every time the process is started, the command to start the jar package needs to be entered in the Linux terminal, which is rather cumbersome, and then try to write the command to start the jar package. In the shell script file, the function of operating the shell script to start the jar package program is realized.
The commands in the socdev.sh script file written are as follows:
1 #The directory where the startup command is located 2 HOME= '/home/pi/Desktop/java' 3 4 #Get the mac address (unique) 5 mac=`ifconfig | grep eth0 | awk '{print $5 }'` 6 7 start( ){ 8 #Enter the directory where the command is located 9 cd $HOME 10 nohup sudo java -jar ufoCatcher-catcher-1.0-SNAPSHOT.jar $mac wss://ip:port /catcher PULL_DOWN & 11 } 12 13 stop(){ 14 # kill all java programs 15 ps -ef | grep java | grep -v grep |awk '{print $2}' | xargs sudo kill -9 16 } 17 18 case $1 in 19 start) 20 start 21 ;; 22 stop) 23 stop 24 ;; 25 restart) 26 $0 stop 27 sleep 2 28 $0 start 29 ;; 30 *) 31 echo "Usage: {start|stop|restart}" 32 ;; 33 esac 34 35 exit 0
Start the jar package program: ./socdev.sh start
Terminate the jar package program: ./socdev.sh stop