Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 23rd, 2008, 10:38 AM   #1
bwasson
Newbie
 
Join Date: Sep 2008
Posts: 4
Rep Power: 0 bwasson is on a distinguished road
BatchFile help!

I am a complete beginner in respect to batch files, and have to get something done at work.

I need to run a bunch of shutdown commands in a batch file, stopping between each command to make sure the machine that was just told to shut down is completely down before i send the next command.
Now, I figured I could run the shutdown command, ping, and if it times out move on. but I have no idea how to process the output of the ping command where it will tell me whether or not it timed out.

I also need to periodically login to certain machines in the scrip using local accounts to run a shutdown command (they are not in the domain) and I haven't the foggiest idea how to do that.
bwasson is offline   Reply With Quote
Old Sep 23rd, 2008, 11:21 AM   #2
Freaky Chris
Professional Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 269
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: BatchFile help!

Google i love it xD

Hint hint second link

Chris
Freaky Chris is offline   Reply With Quote
Old Sep 23rd, 2008, 12:31 PM   #3
bwasson
Newbie
 
Join Date: Sep 2008
Posts: 4
Rep Power: 0 bwasson is on a distinguished road
Re: BatchFile help!

I'll have to see if that will work. I'm still trying to figure out how to implement it.
bwasson is offline   Reply With Quote
Old Sep 23rd, 2008, 12:42 PM   #4
Freaky Chris
Professional Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 269
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: BatchFile help!

probably very nasty syntax, since i never use batch files but here you go

@echo off
:first
ping 192.000.1.1 > %TEMP%\pinglog
find "Request timed out" < %TEMP%\pinglog > nul
if not errorlevel 1 echo Shutdown 192.000.1.1 && goto :next1
goto :first

:next1
ping 192.000.1.2 > %TEMP%\pinglog
find "Request timed out" < %TEMP%\pinglog > nul
if not errorlevel 1 echo Shutdown 192.000.1.2 && goto :next2
goto :next1

:next2
ping 192.000.1.3 > %TEMP%\pinglog
find "Request timed out" < %TEMP%\pinglog > nul
if not errorlevel 1 echo Shutdown 192.000.1.3 && goto :next3
goto :next2


Chris
__________________
Steven Skiena - Algorithms
Freaky Chris is offline   Reply With Quote
Old Sep 23rd, 2008, 2:36 PM   #5
bwasson
Newbie
 
Join Date: Sep 2008
Posts: 4
Rep Power: 0 bwasson is on a distinguished road
Re: BatchFile help!

that code doesn;t seem to work at all when I feel in my information.
each individual statement works, but when run as a whole, it just executes the ping over and over again and never does the shutdown.
bwasson is offline   Reply With Quote
Old Sep 23rd, 2008, 2:50 PM   #6
Freaky Chris
Professional Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 269
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: BatchFile help!

Thats because there is no shutdown command issued since i didn't know what you wanted to run exactly. so ok i suppose yu want something like this
@echo off
shutdown -s -f -t 00 -m 192.000.1.1
:first
ping 192.000.1.1 > %TEMP%\pinglog
find "Request timed out" < %TEMP%\pinglog > nul
if not errorlevel 1 echo Shutdown 192.000.1.1 && goto :next1
goto :first

:next1
shutdown -s -f -t 00 -m 192.000.1.2
:next11
ping 192.000.1.2 > %TEMP%\pinglog
find "Request timed out" < %TEMP%\pinglog > nul
if not errorlevel 1 echo Shutdown 192.000.1.2 && goto :next2
goto :next11

:next2
shutdown -s -f -t 00 -m 192.000.1.3
:next22
ping 192.000.1.3 > %TEMP%\pinglog
find "Request timed out" < %TEMP%\pinglog > nul
if not errorlevel 1 echo Shutdown 192.000.1.3 && goto :next3
goto :next22

ignore the im not sure on ip the code will work fine if you plug in your info.
__________________
Steven Skiena - Algorithms

Last edited by Freaky Chris; Sep 23rd, 2008 at 2:53 PM. Reason: update on IP
Freaky Chris is offline   Reply With Quote
Old Sep 23rd, 2008, 3:46 PM   #7
bwasson
Newbie
 
Join Date: Sep 2008
Posts: 4
Rep Power: 0 bwasson is on a distinguished road
Re: BatchFile help!

With some minor tweaking this worked perfectly!
I'm so freaking happy right now it's not even funny
thank you so much!

Last edited by bwasson; Sep 23rd, 2008 at 4:01 PM.
bwasson is offline   Reply With Quote
Old Sep 23rd, 2008, 4:06 PM   #8
Freaky Chris
Professional Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 269
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: BatchFile help!

Hehe, im glad i could help. Minor tweaks doesn't suprise me its untested and not specific for you. Glad its sorted.

Chris
__________________
Steven Skiena - Algorithms
Freaky Chris is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:38 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC