How to write a script that kills a java process?
From console it looks like
root@ubuntu-s-1vcpu-1gb-ams3-01:~# lsof -i tcp:8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 9657 root 26u IPv6 4694148 0t0 TCP *:http-alt (LISTEN)
root@ubuntu-s-1vcpu-1gb-ams3-01:~# kill 9657
How should it be implemented in .sh file?
Just use the
killall
command. That should work. Like this:(Just in case you don't know how to create a executable .sh file (It's not quite clear): A .sh file should begin with a shebang, something like
After that, you just write commands like you would in a terminal, separated into lines. Then you run
and are able to execute the .sh file just fine.
killall
should be no exception