How to use an application name to kill it from a script
Minecraft Server should be detectable through the arguments passed to its java
process.
Over at Unix & Linux, the question kill process based on arguments tackles this problem: how to kill a specific java process based on its command line arguments.
The top answer recommends using pkill
with the -f
flag to kill based on the arguments associated with a specific process. The final command may be as simple as:
pkill -f 'MinecraftServer'
With regard to using cron
, this is fine but Apple recommend migrating to launchd
as cron
is less efficient.