I have been having troubles setting up an auto reboot for my mc server.
My .sh file I have made works perfectly whenever I execute it, but when it comes to using crontab it seems to just do nothing (excluding one time), I have tried restarting & reinstalling it... it is safe to say I am out of my element as I am completely new to all of this.
The crontab line is this
0 20 * * * /VHServer/reboot.sh
nothing has changed since I made that line of code, it worked the first time and then never again.
The .sh file looks like this and it runs perfectly with a manual command.
echo "Server reboot STARTED"
# Letting people know that the server is going to restart
tmux send-keys -t VHS "/say §c Server restarting in §r§6§l30 minutes. §r§cPleas>
# Wait for 1770 seconds (25 minutes)
sleep 1500s
# Send messages to the server indicating the restart countdown
tmux send-keys -t VHS "/say §c Server is restarting in §r§6§l5 minutes! §r§cThe>
sleep 270s
tmux send-keys -t VHS "/say §c Server is restarting in §r§6§l30 seconds! §r§cTh>
sleep 20s
tmux send-keys -t VHS "/say §c Server is restarting in §r§6§l10 seconds!" Enter
sleep 5s
tmux send-keys -t VHS "/say §c Server is restarting in §r§6§l5 seconds!" Enter
sleep 1s
tmux send-keys -t VHS "/say §c Server is restarting in §r§6§l4 seconds!" Enter
sleep 1s
tmux send-keys -t VHS "/say §c Server is restarting in §r§6§l3 seconds!" Enter
sleep 1s
tmux send-keys -t VHS "/say §c Server is restarting in §r§6§l2 seconds!" Enter
sleep 1s
tmux send-keys -t VHS "/say §c Server is restarting in §r§6§l1 second!" Enter
sleep 1s
# Stop the Minecraft server
tmux send-keys -t VHS "/stop" Enter
sleep 60s
# Detatch from the tmux session
tmux send-keys VHS C-b d
sleep 15s
# Check if the session exists and kills session
if tmux has-session -t VHS> /dev/null; then
echo "Killing tmux session 'VHS'."
tmux kill-session -t VHS
else
echo "Tmux session 'VHS' does not exist."
fi
sleep 15s
# Check if a session with the same name already exists
if tmux has-session -t VHS> /dev/null; then
echo "Tmux session 'VHS' already exists. Attaching to it."
tmux attach-session -t VHS
else
echo "Creating new tmux session 'VHS'."
tmux new-session -s VHS
fi
sleep 30s
# Restart the server using the run.sh script
tmux send-keys -t VHS "/home/ubuntu/VHServer/run.sh" Enter
echo "Server Rebooting"
sleep 60s
echo "reboot COMPLETE"
I have had suggestions to run the crontab using sudo and also adding either sudo or the username "ubuntu" to the line of code within it, I have tried and there has been no output whatsoever.
I ran:
tail -f /var/log/syslog
and this only came back with the edits of the crontab, not once did the cron execute any command.
I hope this is enough information to provide a fix, I am at a complete loss and still learning about all of this, so I am sure I am not understanding something within all of this.