Skip to content

Instantly share code, notes, and snippets.

@aschuhardt
Created September 23, 2020 20:05
Show Gist options
  • Save aschuhardt/0765f10edf733946d69cd1f825421b69 to your computer and use it in GitHub Desktop.
Save aschuhardt/0765f10edf733946d69cd1f825421b69 to your computer and use it in GitHub Desktop.
script to kill a minecraft server that was launched with launch_ftb.sh
if [ ! -f /tmp/ftb-session-name ]; then
echo "No session found! Was the server launched?"
exit 1
fi
command_prefix="screen -S $session_name -p 0 -X stuff "
crontab_file="/tmp/.cronjobs-$(date '+%s')"
session_name="$(cat /tmp/ftb-session-name)"
# dump existing cron jobs to file
crontab -l > $crontab_file
# clean up any cron jobs from prior runs
sed --in-place '/ftb-server-/d' $crontab_file
# load cron jobs and remove temp file
crontab $crontab_file
rm $crontab_file
# stop the server if it's running
screen -S $session_name -p 0 -X stuff 'say stopping the server in 10 seconds...^M'
sleep 10
screen -S $session_name -p 0 -X stuff 'stop^M'
rm /tmp/ftb-session-name
@aschuhardt
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment