How would I setup auto server restarts on a Ubuntu 16 server, I already tried Crontab however I am unable to get it to work (maybe doing it wrong), I want my server to restart every 6 hours which is ran at a screen (some shit that keeps stuff running even when you close the session). Anyone able to help?
#!/bin/bash
SERVERNAME="server_izio"
screen -ls | grep $SERVERNAME | cut -d. -f1 | awk '{print $1}' | xargs kill
screen -S $SERVERNAME -dm bash -c 'sleep 1;cd /home/izio; bash run.sh;exec sh'
echo "Serveur Restart"
1 Like
So I guess you make a .sh file with that code and run it? If so I get a bad interpreter area when I try to run it.
This is what the .sh file looks like, did I do something wrong?
#!/bin/bash
SERVERNAME="eastlspublic"
screen -ls | grep $SERVERNAME | cut -d. -f1 | awk '{print $1}' | xargs kill
screen -S $SERVERNAME -dm bash -c 'sleep 1;cd /home/eastlspublic; bash run.sh;exec sh'
echo "Server Restart"
do you know how to run these scripts with crontab?
I also have this problem I been manually restart the server and I been trying crontab but most of the commands dont work how I use the bin bash?
I tried your script but it doesnt work?
am trying to understand this is there anyway to restart the server with crontab with a command? or I need to do bin bash for this to work?
bash script for the 2 ways
still confused on how to make the server restart