Page 1 of 1 1
Topic Options
#69087 - 2002-08-16 09:47 AM Read only a portion of a string
pommie Offline
Fresh Scripter

Registered: 2002-02-01
Posts: 27
Hi I have the following script which searches a text file for a particular string and outputs the result to another file.

The $string result = "version=123"

Q. Is it possible to seperate the result of the string so only 123 is captured?

Thanks

break on

$TivoliHome = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lcfd\", "run_dir")
$file="$tivolihome\last.cfg"
$string="lcfd_version"

$found = 0

if open(1,$file) = 0
$line = readline(1)
while @error = 0
if instr($line,$string)
$found = 1
if $found = 1
If Open(5,"\\servername\share$\@wksta.csv",5)=0
$RC=WriteLine(5,"Tivoli Version"+Chr(13)+Chr(10))
$RC=WriteLine(5,"$line,")
$RC=Close(5)
endif
endif

endif
$line = readline(1)
loop
$q=close(1)
endif

exit

Top
#69088 - 2002-08-16 10:36 AM Re: Read only a portion of a string
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
See my reply to your earlier posting:
http://81.17.37.55/board/ultimatebb.php?ubb=get_topic;f=1;t=005519

Top
#69089 - 2002-08-16 11:13 AM Re: Read only a portion of a string
pommie Offline
Fresh Scripter

Registered: 2002-02-01
Posts: 27
Hi again,
Many thanks for your advice.
My script has now grown and changed somewhat and appears to work fine on W2K machines but not Win95.

The portion of the script
if open(1,$file) = 0 works ok on W2K, but on Win95 it always returns a 1 and ends the script??

I may get round to your previous advice once this bug is sorted, but these needs to be up and running for Monday morning [Eek!]

Any ideas??

I'm sure my script is not the most efficient in it's operation, as I'm new to this I had to pinch others work and piece it together, so if anyone else has any pointers I'd appreciate it.

Break on

select
case @inwin = 2
;? "This is a Win9x computer"
$os=Win9x
$value = ReadValue("HKEY_LOCAL_MACHINE\software\Symantec\Norton Antivirus\", "currentversion")
$Tivolihome = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices\", "lcfd1")
$file="$tivolihome\last.cfg"
$string="lcfd_version"
$found = 0

case @inwin = 1 and @dos = "4.0"
;? "this is an NT4 computer"
$os=NT4
$NAVHome = ReadValue("HKEY_LOCAL_MACHINE\software\INTEL\LANDesk\VirusProtect6\CurrentVersion\", "Home Directory")
$value = GetFileVersion($NAVHome +"\vpc32.exe","ProductVersion")
$TivoliHome = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lcfd\", "run_dir")
$file="$tivolihome\last.cfg"
$string="lcfd_version"
$found = 0

case @inwin = 1 and @dos = "5.0"
;? "this is a Windows 2000 computer"
$os="WIN 2000"
$NAVHome = ReadValue("HKEY_LOCAL_MACHINE\software\INTEL\LANDesk\VirusProtect6\CurrentVersion\", "Home Directory")
$value = GetFileVersion($NAVHome +"\vpc32.exe","ProductVersion")
$TivoliHome = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lcfd\", "run_dir")
$file="$tivolihome\last.cfg"
$string="lcfd_version"
$found = 0

endselect

$filename='\\Servername\share\@wksta.csv'
IF EXIST($filename)
DEL $filename
ENDIF

if open(1,$file) = 0
$line = readline(1)
while @error = 0
if instr($line,$string)
$found = 1
if $found = 1
goto data
endif
endif
$line = readline(1)
loop
$q=close(1)

endif
exit

:data
If Open(5,"\\servername\share\@wksta.csv",5)=0
$RC=WriteLine(5,"Workstation, OS, User Name, IP Address, Domain Controller, Date, Time, NAV Version, Tivoli Ver"+Chr(13)+Chr(10))
$RC=WriteLine(5,"@WKSTA, $os, @USERID, @IPADDRESS0, @LSERVER, @DATE, @TIME, $value, $line")
$RC=Close(5)
EndIF

Top
#69090 - 2002-08-16 11:39 AM Re: Read only a portion of a string
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I'd change your select to shorter one.

something like:
code:
select
case @inwin = 2
$os=Win9x
$value = ReadValue("HKEY_LOCAL_MACHINE\software\Symantec\Norton Antivirus\", "currentversion")
$Tivolihome = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices\", "lcfd1")

case @inwin = 1 and @dos = "4.0"
$os=NT4
$NAVHome = ReadValue("HKEY_LOCAL_MACHINE\software\INTEL\LANDesk\VirusProtect6\CurrentVersion\", "Home Directory")
$value = GetFileVersion($NAVHome +"\vpc32.exe","ProductVersion")
$TivoliHome = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lcfd\", "run_dir")

case @inwin = 1 and @dos = "5.0"
$os="WIN 2000"
$NAVHome = ReadValue("HKEY_LOCAL_MACHINE\software\INTEL\LANDesk\VirusProtect6\CurrentVersion\", "Home Directory")
$value = GetFileVersion($NAVHome +"\vpc32.exe","ProductVersion")
$TivoliHome = ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lcfd\", "run_dir")
endselect

$file=$Tivolihome+"\last.cfg"
$string="lcfd_version"
$found = 0

anyway, if it says illegal function... not quite sure what would do that.
you could change your if open to something like:
code:
if open(1,$file) ? "error opening file $file" get $nul
else
$line = readline(1)
...

this way it would show you also, what is the file it tries to open and so on...

-
_________________________
!

download KiXnet

Top
#69091 - 2002-08-16 01:28 PM Re: Read only a portion of a string
pommie Offline
Fresh Scripter

Registered: 2002-02-01
Posts: 27
I know what the file is that the script is trying to open.

It's the last.cfg.

It doesnt return any error message, simply exists the script.

If I was to remove the IF Open statement and simply write to the file it works ok.

For W2K machines the script works fine.

Kiitos

Top
#69092 - 2002-08-16 01:38 PM Re: Read only a portion of a string
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
pommie, I know you know so don't thank for nothing.

anyway, I was trying to search for the failing reason. does it output anything with my version or does it just exit?
if it exits does it do it ok or with error.

there is something failing so there must be somekind of error too.
perhaps not in kix but anyway some error there is.

and with exchaustive lookup it should be found out.

...
_________________________
!

download KiXnet

Top
#69093 - 2002-08-19 07:05 AM Re: Read only a portion of a string
pommie Offline
Fresh Scripter

Registered: 2002-02-01
Posts: 27
Hi again,
Your advice worked, I found the problem by displaying the error. It was kind of stupid too (I should have check the Registry).

For the Win95 & 98 clients the registry value they report is

"c:\program files\tivoli\lcf\bin\win95\mrt\lcfd.exe" -C "c:\program files\tivoli\lcf\dat\1"

now I only want to know this bit: c:\program files\tivoli\lcf\dat\1

I havent figured out how to do this yet, but I've been assured that the install dir should not be different, so If decided to simply define the $Tivolihome variable without checking the registry first.

A previous poster showed me how to split a string in two, but I guess here It would be very different?
Is this possible and advised?

Thanks again

Top
#69094 - 2002-08-19 11:55 AM Re: Read only a portion of a string
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mmm...
with split it might be the shortest.
if your readvalue does like this:

$tivolihome='"c:\program files\tivoli\lcf\bin\win95\mrt\lcfd.exe" -C "c:\program files\tivoli\lcf\dat\1"'

then

$tivolihome=split($tivolihome,'"')[3]

indeed is the shortest way.
I might explain it a little.
what split somewhat does is divide string into an array and I divided it with '"'. to get the correct string from there, you just have count what element it is and get it with [3]

cheers...
_________________________
!

download KiXnet

Top
Page 1 of 1 1


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

Who's Online
0 registered and 323 anonymous users online.
Newest Members
Audio, Hoschi, Comet, rrosell, PatrickPinto
17880 Registered Users

Generated in 0.062 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