Page 1 of 1 1
Topic Options
#178968 - 2007-08-08 11:22 PM Validating a File Exists on Remote Computers
JeffS Offline
Fresh Scripter

Registered: 2007-01-17
Posts: 29
Loc: Portland, OR
The basic jist of this is I that the script is reading in a text file that contains all of the computer names in the domain. Ideally what I would like for it to do is go through and validate if this file exists on the computer. If it does, I want it to write to this text file that say the computer name and if the file exists or not.

 Code:
 
Break on

Open(1,"SymForm.txt",2)

Do $Comp = ReadLine(1)
	$UNCComp = "\\"+$Comp

	If Exist("$UNCComp\C$\Program Files\SymForm API\SymStoreMod.dll")=1
		$ToWrite = $Comp+Chr(9)+"File Exists"
		Open(2, "\\servername\sharename\filename.txt", 5)
		WriteLine(2, $ToWrite + @CRLF)
		Close(2)
	Else
		$NoWrite = $Comp+Chr(9)+"File Does Not Exist"
		Open(2, "\\servername\sharename\filename.txt",5)
		WriteLine(2, $NoWrite + @CRLF)
		Close(2)
	EndIf

Until $Comp=""
Close(1)


There are few problems I am experiencing. For testing I typically start with one computer until the code appears to be correct. For some reason everytime I read the one computer name, it will create a valid return in the text file, but then create a new line with no computer name and say File does not exist. Then when I start to read in multiple computers it it throws off all of the records.

For some reason I can't wrap my head around why it isn't working. I am definately open to other ideas of how to validate that this file exist on all of the domain computers. Any suggestions are appreacatied.

Thanks!
Jeff

Top
#178971 - 2007-08-08 11:58 PM Re: Validating a File Exists on Remote Computers [Re: JeffS]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Untested, but should work.

 Code:

; not only good practice, but needed because you are using "C$" in a string
; to specify the admin share!
$ = SetOption('NoVarsInStrings', 'On')

If Open(1,"SymForm.txt",2) = 0

  ; send all output to this file
  $ = RedirectOutput('\\servername\sharename\filename.txt')

  $Comp = ReadLine(1)   ; read the first line
  While Not @ERROR      ; loop until error occurs (End of File)
    If $Comp            ; process if not blank

      ; This wraps the Computer name in \\ and \, removing any slashes that already exist
      $Target = '\\' + Join(Split($Comp, '\'), '', 3) + '\'

      ; this print statement is common to all processing
      $Comp Chr(9) 
      If Exist($Target + 'C$\Program Files\SymForm API\SymStoreMod.dll')
        'File Exists' ?
      Else
        'File Missing' ?
      EndIf

    EndIf
    $Comp = ReadLine(1)	; read the next line
  Loop
  Close(1)

  ; close the output redirection
  $ = RedirectOutput('')

EndIf


RedirectOutput is so much easier to use for this kind of thing. I'd also consider using WriteProfileString to record the status to an ini file.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#178974 - 2007-08-09 01:25 AM Re: Validating a File Exists on Remote Computers [Re: Glenn Barnas]
JeffS Offline
Fresh Scripter

Registered: 2007-01-17
Posts: 29
Loc: Portland, OR
Thanks Glenn!

It works but doesn't work. You are getting the same issue I am. When I place one computer name in the SymForm.txt file I get the correct anwser of 'File Exists' however, once I input multiple computer names into the file, I get 'File Missing' even with computers that I have verified that the file is in the correct folder. So back to square one just with better code! ;-)

Top
#178977 - 2007-08-09 04:08 AM Re: Validating a File Exists on Remote Computers [Re: JeffS]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Try this mod - it should write to the log, but tell you on the command line what is happening. Should display :#, where the # is 0 or 1 - the output of the Exist function. Will also display the exit status of the ReadLine(1) function.

I changed the search path to something I have, and this code works for me - searched 6 servers here and found files, but didn't find them on my kid's XP workstations.
 Code:
; not only good practice, but needed because you are using "C$" in a string
; to specify the admin share!
$ = SetOption('NoVarsInStrings', 'On')

If Open(1,"SymForm.txt",2) = 0

  $Comp = ReadLine(1)	; read the first line
  While Not @ERROR	; loop until error occurs (End of File)
    If $Comp		; process if not blank

      ; This wraps the Computer name in \\ and \, removing any that already exist
      $Target = '\\' + Join(Split($Comp, '\'), '', 3) + '\'

      'Processing ' $Comp ':' Exist($Target + 'C$\Program Files\SymForm API\SymStoreMod.dll') ?      

      ; send all output to this file
      $ = RedirectOutput('\\server\share\filename.txt')

      ; this print statement is common to all processing
      $Comp Chr(9) 
      If Exist($Target + 'C$\Program Files\SymForm API\SymStoreMod.dll')
        'File Exists' ?
      Else
        'File Missing' ?
      EndIf

      $ = RedirectOutput('')

    EndIf
    $Comp = ReadLine(1)	; read the next line
    @SERROR ?
  Loop
  Close(1)

  ; close the output redirection

EndIf
_________________________
Actually I am a Rocket Scientist! \:D

Top
#179066 - 2007-08-10 02:12 AM Re: Validating a File Exists on Remote Computers [Re: Glenn Barnas]
JeffS Offline
Fresh Scripter

Registered: 2007-01-17
Posts: 29
Loc: Portland, OR
Thanks for all of your help Glenn. It was odd, I tried your new code and I was still getting incorrect data back. Frustrated that it wasn't working and it should have been I scratched the code and rewrote a new one just to add to our login scripts. Sometimes it is just easier when you don't have to deal with remote machines and just make it seem local.

Here is the code I ended up with:
 Code:
	;RedirectOut sends all of the output information to the file \\server\share\file
	$ = RedirectOutput('\\server\share\filename')
	
	;Checks to see if SymStoreMod.dll exists
	If Exist("C:\Program Files\SymForm API\SymStoreMod.dll")
		;If file exists than it will run this command
		@WKSTA + Chr(9)+@DATE+Chr(9)'File Exists'?
	Else
		;If the file does not exist will run the following command
		@WKSTA + Chr(9)+@DATE+Chr(9)+'File Does Not Exist' ?
	EndIf
	
	;Closes the output redirection
	$ = RedirectOutput('')

:End 


I am going to let the code run for a few days in the login script and then go through the log file, erase any duplicates and what not, and hopefully get an accurate listing of what computers are missing the DLL file.

Thanks again for your help. Any comments on this new code would be helpful just so I can learn if I am doing things correctly or not.

Top
#179069 - 2007-08-10 02:53 AM Re: Validating a File Exists on Remote Computers [Re: JeffS]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
 Quote:

; not only good practice, but needed because you are using "C$" in a string
; to specify the admin share!
$ = SetOption('NoVarsInStrings', 'On')

heh, since when did vars have $-sign at the end?
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.043 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org