Page 1 of 1 1
Topic Options
#29514 - 2002-09-23 11:19 PM Copying to remote systems & logging it
Anonymous
Unregistered


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.

Top
#29515 - 2002-09-24 03:31 AM Re: Copying to remote systems & logging it
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If you took out the code, how are we to see what's wrong with it?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#29516 - 2002-09-24 04:17 AM Re: Copying to remote systems & logging it
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Take a look at this FAQ,

Topic: File Input/Output Primer

post some code, and we'll have a go at it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#29517 - 2002-09-24 06:45 AM Re: Copying to remote systems & logging it
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Les...

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

Keep your stick on the ice [Wink]
_________________________
We all live in a Yellow Subroutine...

Top
#29518 - 2002-09-24 03:10 PM Re: Copying to remote systems & logging it
Anonymous
Unregistered


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 ]

Top
#29519 - 2002-09-24 03:26 PM Re: Copying to remote systems & logging it
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#29520 - 2002-09-24 03:40 PM Re: Copying to remote systems & logging it
Anonymous
Unregistered


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


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

Who's Online
1 registered (Allen) and 153 anonymous users online.
Newest Members
motkomeri, NHUVY, michaeltoan, scullsol, phanhuyen345
17565 Registered Users

Generated in 0.029 seconds in which 0.01 seconds were spent on a total of 12 queries. Zlib compression enabled.

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