Hello Facepunch, I've been hosting a minecraft server for me and a few friends, and for some reason around 1:30 am the computer just decides to stop talking to the router and we get disconnected and I can't even use teamviewer to connect to it. I have this thing sitting at my fathers house and I'm usually not there, so I have to ask him to go downstairs in the morning to turn the darn thing off the next day, and its been making him a little angry.
So I had an idea for a little script, I despise coding and I'm not very good at it myself, so I was wondering if someone could help me, it seems like an easy enough thing to do.
First, the script would wait 5ish minutes, then ping my router, if it gets a ping back, it'll wait another 5 minutes and ping again, if not, make the computer reboot.
That seems like it could be simple enough, but if it was possible, could it be possible to enter "stop" into the minecraft server window(running in no gui mode, just a cmd prompt), wait a few second for the server to stop, close the window, then reboot? Would be helpful so I can be sure it won't corrupt the map.
To be perfectly honest with you all I don't know if this is even possible, if it isn't could someone point me in the right direction for something similar? Also, if someone can make up something for me, how much of a hit will the cpu take from such a script?
Thanks everyone.
Just wrote this up.
Should detect errors.
Its not the best way of doing it, but...
[code]
sleep x_amount_of_time
if [[ `ping -q -c 1 a_IP | grep errors` != '' ]]; then
echo lol
sleep x_amount_of_time
if [[ `ping -q -c 1 a_IP | grep errors` != '' ]]; then
reboot
fi
fi
[/code]
I would use killall to kill the server.
Restart it like this..
server &
to have it run in the background.
Nice Job Killman.
Why do you despise coding? That's silly.
Thank you killman, however I have a question, what unit of time will this script count in, milliseconds?
[QUOTE=a-k-t-w;26334051]Why do you despise coding? That's silly.[/QUOTE]
Personally I'm a very visual person, Its hard for me to remember all the commands and such, and how to arrange them. However back in High school when I was using the "Alice" program, which is basically a visual java compiler, I got some of the highest grades in my class. I think its just how my brain is wired.
[QUOTE=Ironic Man;26334378]Thank you killman, however I have a question, what unit of time will this script count in, milliseconds?
Personally I'm a very visual person, Its hard for me to remember all the commands and such, and how to arrange them. However back in High school when I was using the "Alice" program, which is basically a visual java compiler, I got some of the highest grades in my class. I think its just how my brain is wired.[/QUOTE]
The sleep command works by default in seconds.
Feel free to 'man sleep' and see what else it can do though.
[QUOTE=killman;26334913]The sleep command works by default in seconds.
Feel free to 'man sleep' and see what else it can do though.[/QUOTE]
What is a "man sleep"?
Man is the manual program.
man sleep brings up the manual on the sleep command.
Press Q to quit out of it.
Actually, I just noticed something.
You're running the Minecraft server on Windows aren't you?
Killman's script is for Linux.
It's understandable because running a Minecraft server on Windows is a rather stupid thing to do, needs a heck of a lot more resources.
It is most certainly possible that I am, in face, an idiot.
So, I copied your script killman, made it into a batch file, and put it the startup folder next to the minecraft server bat file and then I unplugged the ethernet to see if it would work, I set it to 300, which i think is about 5 minutes, then waited and nothing happened. This is what it looks like now:
[code]sleep 300
if [[ `ping -q -c 1 192.168.1.1 | grep errors` != '' ]]; then
echo lol
sleep 300
if [[ `ping -q -c 1 192.168.1.1 | grep errors` != '' ]]; then
reboot
fi
fi[/code]
What did I do wrong? :c
like someone said that script is for Linux and not windows <: so you might want to install linux to an external HD like I did? Just a suggestion:)
[QUOTE=nikomo;26335095]
Actually, I just noticed something.
You're running the Minecraft server on Windows aren't you?
Killman's script is for Linux.
It's understandable because running a Minecraft server on Windows is a rather stupid thing to do, needs a heck of a lot more resources.[/QUOTE]
Yeah I am, the computer is a 2.5 ghz dual core and has 3 gb ram so minecraft still runs fine on it. I have to keep it Windows because Its a backup computer in case any of my family's other computer break. And they're well.. Technologically resistant.
Edit: and thanks for the tip Rocketsnail, I hadn't noticed his edit before.
Just get a cheap OpenVZ VPS with like 512mb guaranteed RAM and 768/1024mb burstable and play on that with your friend.
Thanks Nikomo, but its been working fine so far, I don't want to mess with it. So I've tried coding myself and I've come up with this so far:
EDIT:, now this.
[code]@echo off
title Disconnected Reboot
:start
IF *something* (
SLEEP 600
goto start
) ELSE (
*something to shut down the minecraft server?*
goto reboot
)
:reboot
SHUTDOWN -r -t 5[/code]
Anyone know what to put for the if statement? or if this will work at all?
Also how to shut down the minecraft server safely? If possible
You'd have to pipe save-all and quit into the server program, but I have no idea if that's possible in Windows.
I'll back the map up periodically if I must, but how can I get the computer to reboot if it won't talk to the router?
Why are you trying to fix a problem with some script when it would be much better to fix the real network issue itself?
I've looked at everything, I've updated all firmwares and drivers, changed a lot of ip settings, nothing has worked. And I'm leaving here tomorrow evening so I can't sit here a baby sit the thing in case it decides to blink, it sucks but its all I can think of right now.
My only advice would be to use the system command and manually run commands from the program if it stops getting packets.
Thanks Killman.
So I've been very busy, after looking around I think VBS is better than batch, and I've come up with this so far:
[code]Option Explicit
Dim objFSO, objTextFile
Dim word, space, pingtimes, pingserver, DBipaddress, WshShell, PINGFlag, path
word = "Ping"
Space = ".."
path = "C:\Documents and Settings\Owner\Desktop\log.txt"
pingtimes = 0
pingserver = "Failed"
DBipaddress = "209.85.149.106" ' Set the server IP address
Do While (pingserver = "Failed" and pingtimes <= 2)
if pingtimes > 0 then WScript.Sleep(30000)
Set WshShell = CreateObject("WScript.Shell")
PINGFlag = WshShell.run("ping -n 1 " & DBipaddress, 0, True)
If PINGFlag = 0 Then
pingserver = "OK"
Else
pingserver = "Failed"
End If
pingtimes = pingtimes + 1
Const ForAppending = 8
Set objTextFile = objFSO.OpenTextFile _
(path, ForAppending, True)
objTextFile.WriteLine(word)
objTextFile.Close
Loop
if pingserver = "Failed" then
Set WSHShell = WScript.CreateObject("WScript.Shell")
objTextFile.WriteLine(space)
objTextFile.Close
WScript.Sleep(4000)
WshShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"
end if[/code]
So far, the pinging and restarting parts seem to be functional, but I'm trying to get it to log for me.
At line 21
[code]Set objTextFile = objFSO.OpenTextFile _[/code]
It keeps saying I need a quote or something, I can't figure it out, does anyone know how to fix it?
ew
Nevermind, Thanks everyone that helped
asking the programming forum for a batch script
rate op programming king
Sorry, you need to Log In to post a reply to this thread.