This article mainly introduces the shell script for Linux to start the jar package. It is very good and has reference value. If you need it, refer
Background:
The device of the project needs to run the jar package program to connect to the server through socket and send data. Each time a process is started, you need to enter the command to start the jar package on the Linux terminal, which is cumbersome, then try to write the command to start the jar package to the shell script file to start the jar package program.
The command in the compiled socdev. sh script file is as follows:
| 123456789101112131415161718192021222324252627282930 |
# Directory of the startup commandHOME='/home/pi/Desktop/java'# Obtain the mac address (unique)mac=`ifconfig | grep eth0 | awk '{print $5}'`
start(){ # Enter the command directory cd $HOME nohup sudo java -jar ufoCatcher-catcher-1.0-SNAPSHOT.jar $mac wss://ip:port/catcher PULL_DOWN &}stop(){ # Kill all java programs ps -ef | grep java | grep -v grep |awk '{print $2}' | xargs sudo kill -9}case $1 in start) start ;; stop) stop ;; restart) $0 stop sleep 2 $0 start ;; *) echo "Usage: {start|stop|restart}" ;;esacexit 0 |
Start the jar package program:./socdev. sh start
Terminate the jar package program:./socdev. sh stop
Summary
The above is the shell script for Linux to start the jar package. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. I would like to thank you for your support for the script home website!