LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-15-2010, 10:38 AM   #1
beeblequix
Member
 
Registered: Oct 2005
Location: Tierra Firma, Earth
Distribution: Debian of course...
Posts: 198

Rep: Reputation: 30
Need to write DOS script to monitor the PC's network status


howdy folks,

There are a few PCs on the network that lose network connection every so often -- sometimes these old beasts have a power failure and owing to a bug in the BIOS the NIC doesn't necessarily initialize properly, which requires a reboot to correct it. Got me thinking of a band-aid -- have the PC ping a specific IP address, and if it cannot ping then it forces itself to reboot.

IF I were to write it in BASH I'd do it like this:
#!/bin/bash

HOST=<some meaningful hostname or IP address>

for ipaddy in $HOST
do
count=$(ping -c 1 $HOST | grep 'received' | awk '{print $4}')
if [ "$count" = "0" ]; then
sh usr/bin/reboot
fi
done

In English: send 1 ping to the IP address. Grep through the results to see how many of 1 ping was returned. IF it returns 0 pings then reboot. I'm sure the reboot command would have to be groomed a bit for sudoers but that's beside the point here.


So, HOW do we write something like this for DOS? Stop giggling (lol). No really, I have Windows 2000 & XP machines that need some sort of script or method of knowing (at intervals) of when they're not talking to the Host system, and need to reboot to fix it. I was thinking to write a simple test script, drop it on each of these machines and use the Windows task scheduler to run it every 30 minutes. Ideas? Thx.
 
Old 01-15-2010, 11:02 AM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
You'd need to write a .bat file -or you might install bash for windows on each machine and then run a bash script to do the job. Writing meaningful .bat files is a wonderful exercise if you are plagues by having to much hair on your head, or are unable to afford a haircut. A 30-50 line .bat file can easily be perfected in 1.5 to 2 years....
 
Old 01-17-2010, 02:07 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Code:
ping -n 1 -l 1 <some-address>
if "%ERRORLEVEL%" == "1" shutdown /r

Last edited by smeezekitty; 01-17-2010 at 02:18 PM.
 
Old 01-19-2010, 06:33 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
You can place it inside a loop. Following smeezekitty's post:
Code:
for /l %a in (;;) do (
    ping -n 1 -l 1 <some-address> || shutdown /r
    sleep 30m
)
You can have sleep.exe from gnuwin32. I'm not sure btw if it's just semicolon or comma.

Last edited by konsolebox; 01-19-2010 at 06:35 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Debian- monitor the network status nushi Linux - Newbie 1 07-01-2009 03:41 PM
Trying to write script to change monitor rez and color depth perlabsrat Linux - Newbie 7 03-31-2009 11:25 AM
how to write a script to know problem in network(rsync is going on) abhishekrahel Linux - Server 4 10-24-2008 12:37 AM
Need to write a shell script which will check the GUI login and retuen the status cod bhsk_08 Linux - General 2 10-14-2008 01:08 PM
Simple shell script to monitor network andybrr Programming 2 09-07-2006 11:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration