Page 1 of 2 12>
Topic Options
#33017 - 2002-11-21 12:39 AM Using a list.txt to hit remote machines
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
I'm fairly new to scripting and am not use to the idea of running scripts that "reach out" and hit remote machines. I've never actually seen a full section of code that will allow "me" to pull machine names from a text file that will then "remote" to a machine and kick off a script. Does any one have a full section of code for that task specifically? or know where I can stare at one so I might be able to use it in my script...... [Confused] [Roll Eyes]
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#33018 - 2002-11-21 12:46 AM Re: Using a list.txt to hit remote machines
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If you searched the board for Sealeopard's KSMS, you could see one that is a FULL section of code.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#33019 - 2002-11-21 02:17 AM Re: Using a list.txt to hit remote machines
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
ArchAngel96,
Not trying to dish out just more STFW advice, here is the link to what I speak of.

Topic: KiXtart Systems Management Server (Part II, The Server)

If you think that's too much to drink up, (you did ask for the full monty) then post back and we can discuss general concepts.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#33020 - 2002-11-21 03:38 AM Re: Using a list.txt to hit remote machines
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Basic principle would be to read computername and OS from .INI file. If OS is Windows NT/2000/XP then copy batch file that calls the script to the admin share on the remote computer. Then use the ScheduleTask() UDF to schedule a remote task calling the just copied batch file.

That's the basic principle used in KSMS. However, it has some more stuff in the server script for the off case where a computer might be offline.
_________________________
There are two types of vessels, submarines and targets.

Top
#33021 - 2002-11-21 04:01 AM Re: Using a list.txt to hit remote machines
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
ok.. the info given is a little more than I'm up for at the moment. So let me narrow this down just a little more....

1) I have a list of computers that I need to target.
2) I currently have a script that was designed for the logon.bat, but have realised that more people do not logoff at night as they should.
-my script is using WMI for its query, and as a logon.bat it seems to work perfectly find.

*I would like to use the same base script, hopefully everything with some new addins to target the machines in the list to 'automatically', meaning I don't have to run the script on each machine manually, to kick off the script.

-- the script it self is a hardware inventory script that specifically targets the information my group is looking for --

So now, my major confusion at this point is how the "reaching out" portion of any script works. I beleiave that once I figure this portion out I'll be able to make the additional modifications to ensure the script works.
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#33022 - 2002-11-21 04:10 AM Re: Using a list.txt to hit remote machines
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
WMI can query computers remotely, no need to run code on local workstations. Take a look at the WMIQuery() UDF and read up on WMI.

If you have a client script, then you will still have to tell each client to run the script.

And again, both the KSMS links and my example provide basic concepts on how to accomplish this with client scripts.
_________________________
There are two types of vessels, submarines and targets.

Top
#33023 - 2002-11-21 05:07 AM Re: Using a list.txt to hit remote machines
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
I have the UDF configured.. but how do you tell it the "list" you want to run against?

[ 21. November 2002, 05:29: Message edited by: ArchAngel96 ]
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#33024 - 2002-11-21 05:14 AM Re: Using a list.txt to hit remote machines
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
DId you have a look at the KSMS stuff? Within it is the script 'maintenance_server.kix' that has the code you need. Look for where $SCRIPTINI is declared and then used within the script. You will find a sction like this:

code:
:COMPUTERS
Dim $computernames, $computer, $remoteroot, $macaddress, $waitseconds, $counter, $maxwait

if exist($SCRIPTINI)
$computernames=readprofilestring($SCRIPTINI,'','')

Follow your nose from there.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#33025 - 2002-11-21 05:45 AM Re: Using a list.txt to hit remote machines
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
OK, I just reread the title of this thread and think I may understand your confusion. You say "Using a list.txt" and Jens' code uses an INI file... two separate and very different methodologies.

I strongly advise that you NOT use a TXT file as it is extremely limited, hard to parse, and very difficult to revise. INI files on the other hand, are structured, require a lot less coding, do not need to be parsed line-by-line, and are very easy to revise. All you need to work with INI files are ReadProfileString() and WriteProfileString(). The manual explains their use. INI files do have limitations on file size so it would be helpful to know how many computers and what data will be stored in keys. There is also a possibility of contention with concurrent writes so that should be factored as well. The contention issue is less than with TXT files however.

You can setup INI files in a multitude of ways. You should give careful consideration for future uses of the INI file to prevent needless duplication. If you disect Jens' INI file you will see that the computer names are the section names and that there are specific keys under each section.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#33026 - 2002-11-21 01:07 PM Re: Using a list.txt to hit remote machines
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Les, I have to disagree about the parsing of txt files, it is not as hard as you make it sound [Smile]

here is a UDF that I made and use in a number of scripts.

code:
function LoadFile($file)
;this function will load the contents of a text file into an array
;you can use a ";" in the test file for commenting and those lines will
;not be loaded
dim $nul, $count
dim $temp[5]

$nul = open(1,$file)
while not @error
$temp[$count] = readline(1)
if substr($temp[$count],1,1) <> ";" and $temp[$count] <> ""
$count = $count+1
endif
if $count > ubound($temp)
redim preserve $temp[ubound($temp)+10]
endif
loop
if $count > 0
redim preserve $temp[$count - 1]
else
$temp = ""
endif
$loadfile = $temp
$ = close(1)
endfunction

INI files are good, but the limitations can be a show stopper.

But to load a flat text file, yes will require more code vs a INI file, but you gain much added control/flexibility for a very small price.

Top
#33027 - 2002-11-21 01:20 PM Re: Using a list.txt to hit remote machines
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
For just a list of things a simple text file is sufficient. However, if I need to groups specific information and assign values to e.g. properties of a group, then the .INi file format has it's advantages. Short of using a real database of course or utilizing the registry in case you would exceed the size limitations of a .INI file.

However, with regards to the original question, it doesn't matter where the computer list is generated. The basic principle would be to read a list of computers into an array anf then use
code:
for each $computer in $computerlist
;do stuff
next

_________________________
There are two types of vessels, submarines and targets.

Top
#33028 - 2002-11-21 03:05 PM Re: Using a list.txt to hit remote machines
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Bryce,
I stand by my statement, well sort of...

I should have said harder to parse than INI files. I realize it's not hard. It just takes a bit more code and as such also has a greater probability of contention.

I know size is a limitation but good planning and coding can overcome that.

Where INIs shine is when async data needs to be written.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#33029 - 2002-11-21 09:38 PM Re: Using a list.txt to hit remote machines
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
Ok, so this is what I've done....
Retrieving the list of computers...
code:
$infile="c:\machines.txt" ; <-- contains your machine names, one per line
; read the input file for the computer(s) to be queried
If Open(3, "$infile") = 0
$computerlist = Ucase(Trim(ReadLine(3)))
While @error = 0
For Each $computer in $computerlist
Gosub main ;do stuff
Next
$computer = Ucase(Trim(ReadLine(3)))
Loop
If Close (3) = 0
EndIf
EndIf

but it doesn't seem to reach out to the two machines in my test list. Instead the script still runs locally and I end up with an inventory of my PC.
if you want to look at the rest of the code look here.... My Code
I'm just not getting it.
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#33030 - 2002-11-21 09:46 PM Re: Using a list.txt to hit remote machines
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you are reading only the first line of the file.
_________________________
!

download KiXnet

Top
#33031 - 2002-11-21 10:01 PM Re: Using a list.txt to hit remote machines
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I took liberty to "syntax check" your code.
here is the result:
code:
$infile="c:\machines.txt" ; <-- contains your machine names, one per line
; read the input file for the computer(s) to be queried
If Open(3, "$infile") = 0
$computer = Ucase(Trim(ReadLine(3)))
While @error = 0
Gosub main ;do stuff
$computer = Ucase(Trim(ReadLine(3)))
Loop
$nul=Close(3)
EndIf

_________________________
!

download KiXnet

Top
#33032 - 2002-11-21 10:22 PM Re: Using a list.txt to hit remote machines
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
Ok that made the script a bit faster, thanx. But I must have a problem within the body of the script that I'm missing. I've taken a look at everyone's suggestions and attempted to align my work with the concepts in their's and it still only runs locally. Perhaps my target is too specific for what I'm asking.... I'll have to revisit this again this weekend I think. Thank you all for your help. If anyone is still interest here's the actual file.

My Hardware Inventory 'Grabber' - if it ever works [Confused] [Frown] [Roll Eyes] [Eek!]
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#33033 - 2002-11-21 10:28 PM Re: Using a list.txt to hit remote machines
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
first thing, remove these lines:
code:
  Gosub main ;do stuff
$computer = Ucase(Trim(ReadLine(3)))
Loop
$nul=Close(3)
EndIf

; script main
:main
[code]

and the return at the end of main.
then, before the exit put these lines back:
[CODE]
$computer = Ucase(Trim(ReadLine(3)))
Loop
$nul=Close(3)
EndIf

_________________________
!

download KiXnet

Top
#33034 - 2002-11-21 10:46 PM Re: Using a list.txt to hit remote machines
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
If you want remote info then you will have to query the remote computer. A quick glance at the script posted in the other BBS thread shows that you are querying the local computer. You will have to rewrite the code to query remotely. You should create a UDF like this: RetrieveHardwareInfo($computer)
The UDF itself will take the $computer parameter and query the remote or local computer.

Take a look at the ReadEventlog() UDF which uses WMI to retrieve eventlogs from remote computers. you want to do something similar.

[ 21. November 2002, 22:50: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#33035 - 2002-11-21 11:36 PM Re: Using a list.txt to hit remote machines
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, saying that much would bring the question of saying at least the thread and possibly even a link to code...
_________________________
!

download KiXnet

Top
#33036 - 2002-11-22 10:39 PM Re: Using a list.txt to hit remote machines
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
sealeopard

Do you know if that ReadEventLog() UDF works? I copied it to test and am getting errors:
Calling ReadEventlog: local, EventID, DateScript error: expected expression!
$events=ReadEventlog($eventlog, $eventid, $date)

and I'm assuming this is the link you are referring to:
http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=2;t=003805#000000

Now I don't want to reference this code if it won't work...

[ 22. November 2002, 22:39: Message edited by: ArchAngel96 ]
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.117 seconds in which 0.066 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