LordSphynx Posted August 23, 2007 Posted August 23, 2007 I have made a script that works like a charm for 1 server in my list, but it doesn't continue for the rest of the servers in my serverlist.txt file till EOF. The original script (where it works for 1 server and then stops) is: expandcollapse popup#comments-start Script Name: CheckAlive Script Version: 1.0 Script Creation: 22/08/2007 Script Description: CheckAlive is a Server Testing Script for a Windows Environment. It checks the availability of servers and results with the IP Address and the RIB card. Script Steps: 01/ Check in AD if the server exists 02/ Checks if the server responds to Ping 03/ Retrieves the IP address and the RIB-IP Address for the server #comments-end ; Includes #include <File.au3> #include <GuiConstants.au3> #include <adfunctions.au3> ; Definitions $scriptname = "CheckAlive v1.00" $logo = "C:\$1\scripts\CheckAlive\img\logo.bmp" $username = "username" $password = "pass***" $domain = "PCH" $file = "C:\$1\Scripts\CheckAlive\results.csv" $filebck = "C:\$1\Scripts\CheckAlive\results.bck" $serverfile = "C:\$1\scripts\CheckAlive\config\ServerList.txt" $pingOK = "The server responded correctly to the PING command." $pingKO = "The server did not respond correctly to the PING command." $IPAddressTXT = "The IP Address is: " $RIBIPAddressTXT = "The IP Address of the RIB is: " $ADResultOK = "The server was found in AD and is marked active." $ADResultKO = "The server was not found in AD." ; Check if file exists If FileExists ($file) Then FileMove ($file, $filebck, 1) MsgBox (4096, $scriptname, "A result file was allready found, it has been copied to results.bck !", 10) FileDelete ($file) _FileCreate($file) Else _FileCreate($file) EndIf ; Write the standard attributes to the File $OpenFile = FileOpen($file, 1) FileWriteLine($OpenFile, "SERVER;ADResult;PingResult;IP Address; RIB IP Address") ; Creation of the Graphical User Interface (GUI) GuiCreate ($scriptname, 400, 450, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $output = GuiCtrlCreateEdit($scriptname & " Console Window" & @CRLF, 0,200,400,175,$ES_AUTOVSCROLL + $WS_VSCROLL + $ES_READONLY, $WS_EX_STATICEDGE) $Pic1 = GuiCtrlCreatePic($logo, 100, 20, 205,154) GuiSetState() $server = FileReadLine($serverfile) ; PING COMMAND GuiCtrlSetData($output, GuiCtrlRead($output) & "Sending PING command to " & $server & @CRLF) $PingIt = ping($server) If $PingIt Then GuiCtrlSetData($output, GuiCtrlRead($output) & $server & ": " & $pingOK & @CRLF) $PingResult = "Ping OK" Else GuiCtrlSetData($output, GuiCtrlRead($output) & $server & ": " & $pingKO & @CRLF) $PingResult = "Ping KO" EndIf ;GETIP $serverip = TCPNameToIP($server) GuiCtrlSetData($output, GuiCtrlRead($output) & $IPAddressTXT & $serverip & @CRLF) ;GETRIBIP $PingRIB = ping("rib-" & $server) If $PingRIB Then GuiCtrlSetData($output, GuiCtrlRead($output) & "The RIB Card responded correctly to the PING command." & @CRLF) $RIBIP = TCPNameToIP("rib-" & $server) GuiCtrlSetData($output, GuiCtrlRead($output) & $RIBIPAddressTXT & $RIBIP & @CRLF) Else GuiCtrlSetData($output, GuiCtrlRead($output) & "The RIB Card did not respond correctly to the PING command." & @CRLF) EndIf ;GENERATE RESULT.CSV File FileWriteLine($OpenFile, $server & ";No AD info available;" & $PingResult & ";" & $serverip & ";" & $RIBIP & @CRLF) FileClose($serverfile) FileClose($OpenFile) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;; EndSelect WEnd Exit ;WEndoÝ÷ Ø¥·w+kçm¢)Üç^kbæî¶+ajËhmì+¢x,¢g°êÞmçºÇ¢¶Ø^È^rMlz»Þ®Þ©Ý¢÷«j¢8^Â¥x§r[yجjëh×6#comments-start Script Name: CheckAlive Script Version: 1.0 Script Creation: 22/08/2007 Script Description: CheckAlive is a Server Testing Script for a Windows Environment. It checks the availability of servers and results with the IP Address and the RIB card. Script Steps: 01/ Check in AD if the server exists 02/ Checks if the server responds to Ping 03/ Retrieves the IP address and the RIB-IP Address for the server #comments-end ; Includes #include <File.au3> #include <GuiConstants.au3> #include <adfunctions.au3> ; Definitions $scriptname = "CheckAlive v1.00" $logo = "C:\$1\scripts\CheckAlive\img\logo.bmp" $username = "username" $password = "pass***" $domain = "PCH" $file = "C:\$1\Scripts\CheckAlive\results.csv" $filebck = "C:\$1\Scripts\CheckAlive\results.bck" $serverfile = "C:\$1\scripts\CheckAlive\config\ServerList.txt" $pingOK = "The server responded correctly to the PING command." $pingKO = "The server did not respond correctly to the PING command." $IPAddressTXT = "The IP Address is: " $RIBIPAddressTXT = "The IP Address of the RIB is: " $ADResultOK = "The server was found in AD and is marked active." $ADResultKO = "The server was not found in AD." ; Check if file exists If FileExists ($file) Then FileMove ($file, $filebck, 1) MsgBox (4096, $scriptname, "A result file was allready found, it has been copied to results.bck !", 10) FileDelete ($file) _FileCreate($file) Else _FileCreate($file) EndIf ; Write the standard attributes to the File $OpenFile = FileOpen($file, 1) FileWriteLine($OpenFile, "SERVER;ADResult;PingResult;IP Address; RIB IP Address") ; Creation of the Graphical User Interface (GUI) GuiCreate ($scriptname, 400, 450, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $output = GuiCtrlCreateEdit($scriptname & " Console Window" & @CRLF, 0,200,400,175,$ES_AUTOVSCROLL + $WS_VSCROLL + $ES_READONLY, $WS_EX_STATICEDGE) $Pic1 = GuiCtrlCreatePic($logo, 100, 20, 205,154) GuiSetState() While 1 $server = FileReadLine($serverfile) If @error = -1 Then ExitLoop ; PING COMMAND GuiCtrlSetData($output, GuiCtrlRead($output) & "Sending PING command to " & $server & @CRLF) $PingIt = ping($server) If $PingIt Then GuiCtrlSetData($output, GuiCtrlRead($output) & $server & ": " & $pingOK & @CRLF) $PingResult = "Ping OK" Else GuiCtrlSetData($output, GuiCtrlRead($output) & $server & ": " & $pingKO & @CRLF) $PingResult = "Ping KO" EndIf ;GETIP $serverip = TCPNameToIP($server) GuiCtrlSetData($output, GuiCtrlRead($output) & $IPAddressTXT & $serverip & @CRLF) ;GETRIBIP $PingRIB = ping("rib-" & $server) If $PingRIB Then GuiCtrlSetData($output, GuiCtrlRead($output) & "The RIB Card responded correctly to the PING command." & @CRLF) $RIBIP = TCPNameToIP("rib-" & $server) GuiCtrlSetData($output, GuiCtrlRead($output) & $RIBIPAddressTXT & $RIBIP & @CRLF) Else GuiCtrlSetData($output, GuiCtrlRead($output) & "The RIB Card did not respond correctly to the PING command." & @CRLF) EndIf WEnd ;GENERATE RESULT.CSV File FileWriteLine($OpenFile, $server & ";No AD info available;" & $PingResult & ";" & $serverip & ";" & $RIBIP & @CRLF) FileClose($serverfile) FileClose($OpenFile) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;; EndSelect WEnd Exit ;WEnd Can someone take a look and tell me where to place the while correctly ? Thanks
Danny35d Posted August 23, 2007 Posted August 23, 2007 (edited) Add the following line right before your first while...loop.$OpenServerList = FileOpen($serverfile, 0)and change this line$server = FileReadLine($serverfile)for$server = FileReadLine($OpenServerList)and at the end of the while...loop addFileClose($OpenServerList)Note: you just forgot to use FileOpen() to be able to read the entire text file. Edited August 23, 2007 by Danny35d AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now