![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2008
Posts: 4
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Professional Programmer
|
Re: BatchFile help!
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Sep 2008
Posts: 4
Rep Power: 0
![]() |
Re: BatchFile help!
I'll have to see if that will work. I'm still trying to figure out how to implement it.
|
|
|
|
|
|
#4 |
|
Professional Programmer
|
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 |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Sep 2008
Posts: 4
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#6 |
|
Professional Programmer
|
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 |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Sep 2008
Posts: 4
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#8 |
|
Professional Programmer
|
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|