#149452 - 2005-10-07 04:09 PM
Readline
|
Niro
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
|
|
|
|
#149454 - 2005-10-07 08:56 PM
Re: Readline
|
Niro
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
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
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
|
|
|
|
#149458 - 2005-10-07 09:23 PM
Re: Readline
|
Niro
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
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
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
|
|
|
|
#149462 - 2005-10-07 11:16 PM
Re: Readline
|
NTDOC
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
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
|
|
|
|
#149465 - 2005-10-10 03:50 PM
Re: Readline
|
Niro
Fresh Scripter
Registered: 2003-07-15
Posts: 41
|
yup that worked perfectly...thanks alot for all your guys' help!
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 781 anonymous users online.
|
|
|