**DONOTDELETE**
(Lurker)
2002-09-23 11:19 PM
Copying to remote systems & logging it

Background: I administer a few dozen win2k pcs that are part of a huge, vast network. I am not a domain admin and I don't have access to a server. All I have is the password for the local admin accounts on all of the win2k boxes.

I wrote a little script to connect to our PCs and copy a file (copying a text file to the desktop is just a test - cause it's easy to check if it worked). Here's the script:
code:
if open (1,"s:\computing\scripts\PCNames.txt") = 0
$pcname = ReadLine(1)
WHILE @ERROR = 0
;? $pcname
gosub "map"
$pcname = ReadLine(1)
LOOP
endif
goto "end"

:map
shell "net use l: \\" + $pcname + "\c$ /user:" + $pcname + "\administrator xxxxxxxxx"
copy s:\computing\scripts\pcnames.txt l:\DOCUME~1\ALLUSE~1\Desktop\pcnames.txt
; this IF EXIST is just for me to see on the screen where it works and where it doesn't
if exist ("l:\DOCUME~1\ALLUSE~1\Desktop\pcnames.txt")
? $pcname + "File exists..."
else
? $pcname + "File didn't exist..."
endif
;? $pcname + ".... Copy Error: " + @error
shell "net use l: /delete"
return

:end
close(1)

It's not pretty, but it works. The PC names are stored in the PCNames.txt file

What I can't get to work is this. I'd like a log file to be created that says which PC this worked on and which one it didn't and the date and time I ran the script. The only way I could think of to test if it worked was to test if the file is in the location where it was supposed to be copied to.

When I try to write a log, the first line for the first PC writes, but nothing after. Can someone help me? [BTW, in case it isn't obvious, I took out the failed code for writing the log file from the script above].

And, of course, if there's a better way to do this I sure would appreciate someone telling me how. Many thanks.


Les
(KiX Master)
2002-09-24 03:31 AM
Re: Copying to remote systems & logging it

If you took out the code, how are we to see what's wrong with it?

Les
(KiX Master)
2002-09-24 04:17 AM
Re: Copying to remote systems & logging it

Take a look at this FAQ,

Topic: File Input/Output Primer

post some code, and we'll have a go at it.


Waltz
(Seasoned Scripter)
2002-09-24 06:45 AM
Re: Copying to remote systems & logging it

Les...

code:
setlogic(hide)
setdebug(off)
dowhatyou'rethinking(now)

Keep your stick on the ice [Wink]


**DONOTDELETE**
(Lurker)
2002-09-24 03:10 PM
Re: Copying to remote systems & logging it

I took out the code cause it was just plain bad...

Now for the odd part. I ran the script again this morning and it works. I didn't change a thing.

Here it is:
code:
if open (1,"s:\computing\scripts\PCNames.txt") = 0
$pcname = ReadLine(1)
WHILE @ERROR = 0
;? $pcname
gosub "map"
$pcname = ReadLine(1)
LOOP
endif
goto "end"

:map
shell "net use l: \\" + $pcname + "\c$ /user:" + $pcname + "\administrator xxxxxx"
copy s:\computing\scripts\pcnames.txt l:\DOCUME~1\ALLUSE~1\Desktop\pcnames.txt
if open(2,"S:\computing\scripts\cpstart.log",5) = 0
if exist ("l:\DOCUME~1\ALLUSE~1\Desktop\pcnames.txt")
? $pcname + "File exists..."
writeline(2, $pcname + chr(9) + "Yes" + @CRLF)
else
? $pcname + "File didn't exist..."
writeline(2, $pcname + chr(9) + "No" + @CRLF)
endif
close(2)
endif
;? $pcname + ".... Copy Error: " + @error
shell "net use l: /delete"
return

:end
close(1)

So is there a better way to do all of this?

[ 24. September 2002, 15:23: Message edited by: Shane ]


Sealeopard
(KiX Master)
2002-09-24 03:26 PM
Re: Copying to remote systems & logging it

Do not use the abbreviated 8.3 DOS names for long file/folder names. There is no guarantee that 'Documents And Settings' will always translate to 'DOCUME~1' on all Windows machines.

also, put your PC names into an .INI file. It is much easier to read a .INI file with READPROFILESTRING, and you can read a whole bunch of computernames with one line and convert the list into an array. Also, there is no reason to have a separate GOSUB routine for the copying since you always call it from the same spot. I would therefore include it into the READLINE segment.


**DONOTDELETE**
(Lurker)
2002-09-24 03:40 PM
Re: Copying to remote systems & logging it

Thanks for the suggestions, Jens. Better learn how to work with arrays and ini files...