Re: How to read text files on remote servers without mapping/unmapping drives?

Tech-Archive recommends: Fix windows errors by optimizing your registry




"Pegasus (MVP)" <I.can@xxxxxxxxxx> wrote in message
news:%23VcmAagiIHA.5160@xxxxxxxxxxxxxxxxxxxxxxx

<Hoa.Hoa.Nguyen@xxxxxxxxx> wrote in message
news:df8d01cc-320b-46c1-a5c2-3df747201d55@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1) We have a script that maps and unmaps drives.
This script is an audit script. So it is called say from Box1 to
BoxA, BoxB, BoxZ etc...
To find out where BoxA-BoxZ have been running backups, the script
interrogates
the backup logs on BoxA-BoxZ.

To read the BoxA-BoxZ the script maps a drive ( V: in this
instance)

objNetwork.MapNetworkDrive "V:", "\\" & strComputer & "\" & "C$", ,
strUser, strPwd
and open to read the back up logs
strFilePath = "V:\Program Files\Tivoli\TSM\baclient
\dsmsched.log"

When finished the drive gets disconnected/unmapped.

If there multiple script jobs running concurrently, this could be a
problem as there could be a job querying the log file as the volume
could have been dismounted from another job.

What would be the best way to read the log on a server without
mounting the drives?

2) Another reason for mounting the drives,
there are some windows commands like "ipconfig" we usually run the
command, save as a text file
errReturn = objProc.Create ("cmd.exe /c ipconfig > C:\temp
\ipview.txt", Null, Null, intPID)

Is there a better way of executing command and read the output
directly without having to creating an extra file?

1) You could use the objFSO object to open a file, using the
UNC naming convention ("\\Server\Share\FileName.Ext").
2) You could use the .exec method to read the output from ipconfig
without an intermediate file:
Set ObjWshShell = WScript.CreateObject("WScript.Shell")
Set ObjExec = ObjWshShell.Exec("ipconfig.exe /all")
Do While Not ObjExec.StdOut.AtEndOfStream
WScript.Echo ObjExec.StdOut.ReadLine 'Read a line
Loop

I generally prefer to collect the output with a single ReadAll, as in:
' sMsg = sMsg & ObjExec.StdOut.ReadLine 'Read a line
sMsg = sMsg & ObjExec.StdOut.ReadAll 'Read everything available

Even with large output, such as a 16 megabyte directory listing, the
loop count is only one in the sample script above.

One nice thing about using the ReadLine method is that it has a fairly
flexible definition of what separates lines; it properly handles two
carriage returns and a line feed that ipconfig.exe uses as its line
separator.

-Paul Randall


.



Relevant Pages