Just looking for a correction/addition to this cannibalized restart code for (originally a Minecraft server, though that is not what it's used for now).
#echo off
title Server Restarter
color 0A
cls
#%SystemRoot%\system32\ping.exe -n 1 xxx.xxx.x.xx
pause
:start
Call Server.bat
cls
pause
This currently does a very simple job: calls server.bat and starts the server. It has none of the bells and whistles I'd like it to have though.
The output of ping is not functional at the moment.
The goal:
Ping to see if a specific IP (and maybe ports) are reachable.
If they are not reachable, close any current instances of Server.exe
Continue pinging until specific IP is reachable.
Once the IP is reachable, call server.bat
It needs to ping at intervals of ~30 seconds.
Some context for why it's needed:
The game server does not currently close its process regardless of it being online or not, it continues to run in the process window. That's why I need it close any current instances, else we just end up with multiples of the same server running.
The server is run from a local computer using direct IP connection, therefore if the local computer isn't connected to the internet, the server wont be reachable to anyone (obviously). The intent for the .bat is to run continuously so even when the user isn't at the computer, it will take care of ensuring the server is online 24/7.
This will be a file I will want to make available to other server hosts who may want to use it to keep themselves online 24/7.
The port check will be to ensure the master server ports are reachable and the fault is/isn't on their side, this is not essential so if it's too much trouble, don't worry.
Inside "Server.bat":
#echo off
echo Server process starting
echo Ctrl+Alt+Del to Kill
Server.exe -batchmode -nographics
All of your assistance and comments are very much welcomed. I tried to generalize this as much as possible to keep it simple, so it can be altered for anyone else who may find use for it with any application.
Sounds like you're working on or with a Windows machine. Power Shell might be an option to write your scripts. I came across this question after investigating Test-Connection and Test-NetConnection, which are both kind of like ping, and the latter lets you test if a port is open. Not sure if there are batch file commands like those, but Power Shell lets you use most batch commands. Both of these commands have tons of examples online, and are very easy to use in your use-case.
You probably want to have a while (true) loop running, and periodically do your ping/port checks. That will satisfy your continual checking requirement. Start-Sleep is a cmdlet to let you pause your script, which you'll want to do in your forever loop.
You can call batch files from Power Shell (another link from another good resource), so that will let you reuse your existing scripts if you don't want to rewrite them in Power Shell.
Related
I'm working with server automation tools on some Dell C2100 and C1100 servers. What I intend to do is connecting via Serial Over Lan using ipmi.
A few weeks ago, I was able to connect to one of my servers using ipmi-console (from freeipmi), like this:
ipmi-console -h IPADDRESS -u USER -P
This started up a SOL connection, and this way I was able to automate some interactions with the server's BIOS settings and other stuff.
However, a few days later, the same script didn't work anymore. It just says "[SOL established]", and that's it: the SOL connection never shows any feedback, and it stays idle until I close the connection.
My question is: what could possibly have changed that the SOL connection is not working anymore.
I obviously checked for anything related to SOL and IPMI, both in BIOS settings and using BMC web GUI. But everything looks normal, and I didn't recall to have changed anything there between the time the connections worked and then they stopped working. IDK what else to check, and it just fails w/o errors anywhere.
Perhaps this is a common thing with IPMI and/or SOL, but I frankly don't understand it. So, any pointer would be nice.
Thanks in advance.
FreeIPMI maintainer here. When no data is being output, it is typically a configuration problem. Assuming none of that changed, one idea.
On some motherboards, I've seen the BMC internally "lose its connection" to the serial chip, thus it doesn't get any serial data and thus doesn't have anything to send out. Unfortunately a hard power reset is often needed to solve this (b/c the BMC always is "on" via standby power, it must be a hard reset to reset it). Hard resetting the BMC directly might work as well, you can do this in FreeIPMI via bmc-device --cold-reset.
Finally, I've found what was going on.
It happened that somehow a value DID change on the BIOS settings, most likely my own mistake: remote connection ability was disabled. That means, it seems, that SOL works, but it doesn't redirect anything. Given that I was able to connect through SOL, it seemed obvious that remote connection ability was enabled.
Once enabled that BIOS setting, everything was back to normal.
BTW: freeipmi is awesome. Thanks for maintaining it Albert.
I'm looking for a way to determine whether my internet connection is based on wifi, ethernet, or cellular with a Batch script. My end goal is to have a script run on startup that determines what the connection type is, and as long as it isn't cellular, start a certain application. How can I determine the type of internet connection?
Thanks for any help or ideas!
(I'm a relative newbie at batch, so I would really appreciate all the detail you could give me)
wmic nic where "NetEnabled=TRUE" get description |find "Mobile Broadband" >nul && (
echo Mobile connection active
) || (
echo Mobile connection inactive
)
get all network adapters that are connected and look, if Mobile Broadband" is among them. Execute commands if yes (&&) and other commands, if not (||`)
You might need to adapt the string Mobile Broadband to your actual hardware.
Note: just because it's activ, it doesn't mean, your traffic runs through it; there might be more than one activ adapter.
I made a back-end server which redirects users who abuse the main server (via too many invalid webpage requests in a short time) to another port so that the load on the server will be slightly less.
I then in my program via a exec() issue this command to block the IP from regular service:
iptables -t nat -I <tableforport> -p tcp --src <offending ip> -j REDIRECT --to-port <port of my server>
The problem is when I test this using an actual 2-computer setup where one is the client spamming the server (I'm actually holding F5 down for a few minutes to test), The internal port redirection doesn't seem to kick in right away. If I pause from holding F5 down for a few minutes then try again, then the internal redirection works and the blocking message from my server software works.
I feel this is due to linux (which the server runs on) caching remote IP address entries along with its ports along with other instructions causing the new iptables rules (like the one above) to be skipped until the routing cache is flushed for that IP.
In linux, I can easily flush the routing cache for each IP version via:
echo 1 > /proc/sys/net/ipvn/route/flush
where n in ipvn is either a 4 or 6.
The problem with that is if I execute it, then all the good IP's in cache will be flushed which in turn creates a slower experience for all. I only want to create a bad experience to potential hackers.
How do I go about removing only one IP address from the route cache so that when I add a redirection rule to iptables (like above), the redirection takes place right away the moment the client refreshes the page (not several refreshes, seconds or minutes later)?
Once I get an answer, I want to be able to make a C program out of it after which I can probably figure out myself.
here is the situation:
I have written a C program doing some wireless measurements on a WRT54GL Router (OpenWRT White Russian, Busybox 1.00, Dropbear client v0.49). Please note that i can not use a more up to date version of the operating system on the router or install additional packages (just scripts or small programs are allowed).
Up to now, i log my measurements results every 15 minutes from the router to the server via a
cat localfile | ssh target_address cat ">" remotefile
which i call from my C program (system()) for every logfile which is created or present at the moment the log starts. What i don't like is, that the system call opens a new shell for every single call, causing some overhead. The good thing is that in this way the data is encrypted and because i do a connection for every file, i can directly get per file feedback from the server, so that i can remove the logs from the router. (Other approaches calling scripts from the router on the server, which then return values for the logging did not work, as the dropbear ssh client does not support this return).
So what i'm asking for: what could be a more elegant way to do so and to reduce this overhead ? By now, i've read a few tutorials about how to use TLS / TCP Sockets (so i can send the data encrypted to the server). Another possibility could be a HTTP PUT or POST, but there i am not sure how i could get feedback for the data being send. So i would just like to hear your oppions and how you guys would try to tackle this.
Best regards
Since you're talking about log files, this sounds like a job for the syslog protocol.
I am pretty sure OpenWRT supports it out of the box.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Not strictly a programming question, but I was programming at the time and couldn't find an answer, so I thought, "Hey, I'll give StackOverflow a try!"
So I'm connected to my Windows XP work PC over a Remote Desktop connection through VPN. In a command window (on the remote PC), I foolishly type ipconfig /release. A split second before I come to my senses, I hit Enter. D'oh!
So what now? Am I hosed until I get to the office Monday morning? Any way to remotely make my office PC get itself a new IP address?
If it makes you feel any better, most of us have done something similar. I can't offer a suggestion that doesn't involve human intervention, but I can offer two ways to prevent a "next time" for you:
Look into a remote power controller. Cheap (inexpensive, hobbyist-grade) options are available through www.x10.com; other vendors (Pulizzi, DataProbe, etc.) provide more reliable solutions for a higher price. You may even be able to find a UPS that allows you to control it via a serial port.
Plug your PC into the power controller, and find a second PC to control it. Now you can reboot your PC remotely, no matter how badly you de-configure it.
Anticipate and compensate. It's reasonable to expect that you may need to release/renew the IP address again, so write a utility that will check for the loss of IP address and reboot if that occurs. For example, ping your default gateway and reboot if the ping fails consistently. Just be sure to anticipate the consequences of an unexpected reboot!
Try giving a call to the office and get someone(if any) to restart your computer or ipconfig /renew
What you need to do, is find some way to cut the power to your PC. Many PCs are configured by default to reboot if there is a power failure. So, just hack into your power grid, and shut off power to the entire building. Once your computer reboots, along with all the other equipment, your computer should have it's IP back.
(This probably won't work)
I think if you get your network connection severed, it'll reset (like, if I run ipconfig /release, then shut off my router and restart it, I get a new IP).
It'd be well winging it, but if I was desperate I'd hook up to my DHCP server and reboot it.. I predict the end result would be me still not being able to connect, and the admins giving me a good whipping.
Log into the managed switch the PC is connected to, shutdown the port, wait a few seconds, and then bring it back up. If you don't have a managed switch or no access to it, wait until Monday.