Page 1 of 1 1
Topic Options
#149452 - 2005-10-07 04:09 PM Readline
Niro Offline
Fresh Scripter

Registered: 2003-07-15
Posts: 41
I have a text file formatted like this:

computername,garbage,garbage,etc
computername2,garbage,garbage,etc

I need to be able to take the computername before the comma and put it into a variable so i can pass another command...I'm just not sure how to do that...I know how to open the file and readline, but I can't figure out how to only take out the string before the comma and then go to the next line....left() doesn't work since computer name lengths vary.

Top
#149453 - 2005-10-07 04:19 PM Re: Readline
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
$Line = ReadLine(1)
$Name = Split($Line,',')[0]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#149454 - 2005-10-07 08:56 PM Re: Readline
Niro Offline
Fresh Scripter

Registered: 2003-07-15
Posts: 41
perfect I got it thanks. Now is there anyway for kix to ping a machine, if it gets a response run some more commands otherwise skip that machine?
Top
#149455 - 2005-10-07 09:04 PM Re: Readline
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
something like this...
Code:

Shell '%comspec% /c ping ' + $name + ' -n 1 | find "TTL" > nul'
If not @ERROR
;run you commands
;
EndIf


Top
#149456 - 2005-10-07 09:06 PM Re: Readline
xpanmanx Offline
Starting to like KiXtart

Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
ALIVE.EXE Version 1.2 : Ping utility that returns ERRORLEVEL

http://tinyurl.com/a87xl

Top
#149457 - 2005-10-07 09:17 PM Re: Readline
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Yeah, but why go with an external utility when all your systems will have PING which also has errorlevel
Top
#149458 - 2005-10-07 09:23 PM Re: Readline
Niro Offline
Fresh Scripter

Registered: 2003-07-15
Posts: 41
So here's what I have:
Code:

if open(1,"c:\computers2.txt",2) = 0
while @ERROR = 0
$line = readline(1)
$computer = Split($line,",")[0]
SHELL "C:\ALIVE /repeat=2 " + $computer
If not @ERROR
shell "C:\pstools\psloggedon \\" + $computer
EndIf
LOOP
CLOSE (1)
Endif



Problem is when alive returns an errorcode when a computer isn't alive, the entire loop ends. Anyway around that?


Edited by Niro (2005-10-07 09:25 PM)

Top
#149459 - 2005-10-07 09:39 PM Re: Readline
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Code:
if open(1,"c:\computers2.txt",2) = 0
$line = readline(1)
while @ERROR = 0
$computer = Split($line,",")[0]
SHELL "C:\ALIVE /repeat=2 " + $computer
If not @ERROR
shell "C:\pstools\psloggedon \\" + $computer
EndIf
$line = readline(1)
LOOP
CLOSE (1)
Endif



Edited by Bryce (2005-10-07 09:39 PM)

Top
#149460 - 2005-10-07 10:15 PM Re: Readline
Niro Offline
Fresh Scripter

Registered: 2003-07-15
Posts: 41
lol ok last question I promise...now I need to redirect the output of the psloggedon to a file...I just can't figure out how the redirectoutput() command works:

Code:

if open(1,"c:\computers2.txt",2) = 0
$line = readline(1)
while @ERROR = 0
$computer = Split($line,",")[0]
SHELL "C:\ALIVE /repeat=2 " + $computer
If not @ERROR
open(2,"C:\users.txt",5)
writeline(2, $computer + @CRLF)
close(2)
redirectoutput("c:\users.txt",0)
shell "C:\pstools\psloggedon \\" + $computer
EndIf
$line = readline(1)
LOOP
CLOSE (1)
Endif


Top
#149461 - 2005-10-07 10:41 PM Re: Readline
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

Yeah, but why go with an external utility when all your systems will have PING which also has errorlevel



Actually, it is the errorlevel of FIND that you want, not PING!

Take a look at some of the Pipe() UDFs.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#149462 - 2005-10-07 11:16 PM Re: Readline
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Correct. I thought about that after I posted and just said - Ah the heck with it. Les will point it out soon enough
Top
#149463 - 2005-10-10 03:40 PM Re: Readline
Niro Offline
Fresh Scripter

Registered: 2003-07-15
Posts: 41
lol ok I think I'm almost there...now I'm getting this error with the pipe command...
Code:

$output = pipe("C:\pstools\psloggedon \\" + $computer)
writeline(2, $output + @CRLF)



ERROR : Error in expression: this type of array not supported in expressions.!
Script: c:\pctest.kix
Line : 11

line 11 is the writeline...so since the writeline doesn't work...how do I place the contents of that array into a file??

Thanks!

Top
#149464 - 2005-10-10 03:43 PM Re: Readline
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
pipe returns an array value...

$output = join(pipe("C:\pstools\psloggedon \\" + $computer),@crlf)

should turn it back into a string.

Top
#149465 - 2005-10-10 03:50 PM Re: Readline
Niro Offline
Fresh Scripter

Registered: 2003-07-15
Posts: 41
yup that worked perfectly...thanks alot for all your guys' help!
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
0 registered and 484 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.068 seconds in which 0.028 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