Page 1 of 1 1
Topic Options
#57926 - 2001-08-03 03:48 PM Parsing Text
Anonymous
Unregistered


I have a file that looks something like this.

IPAQ02925=,djames,Daniel James,00D0B7B4C292,8/3/2001,5:32:10
CCARTER=,ccarter,Candy Carter,00508BF5B653,8/2/2001,7:40:18
MULTIRMB113=,rgeske,Robert Geske,000347167CFC,8/1/2001,6:37:28
SFF02987=,kplatt,Ken Platt,0002A575E788,8/2/2001,7:03:03
MIKESTA=,robertm,Robert Mullinax,00D0B7AB20EE,8/3/2001,6:40:57
SFF03214=,kmitchell,Kathryn Mitchell,0002A51D7BB8,8/3/2001,6:38:37

I need to find a way to parse this file for the Computer name (Being the first entry of each line(without the =)) and the Date (being the second to last entry of every line) and calculate the date of the machines last logon compared to todays date. Can anyone help send me in the right direction.

Thanks

Top
#57927 - 2001-08-03 04:49 PM Re: Parsing Text
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I don't know what version of kix you are using, but here is how to do it with kix2001.
time calculation is something you can find out for yourself by BB's search feature.
here is the rest part where $date is the date and $name is the name
code:

$file = "your_file"
$ = open(1,$file)
$line = readline(1)
while @error = 0
$temp = split($line,",")
$name = substr($temp[0],1,len($temp[0])-1)
$date = $temp[5]
;do time compare here
;and with result do something.
$line = readline(1)
loop

_________________________
!

download KiXnet

Top
#57928 - 2001-08-06 04:03 PM Re: Parsing Text
Anonymous
Unregistered


Thanks, That worked great. Do you think that you can help me with one other thing. I need a way to create a list of computers that it will exclude. So how do I create a text file that lists the machines that I want to exclude and has the script read from this.
Top
#57929 - 2001-08-06 04:15 PM Re: Parsing Text
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
have a list file?
well there are more than just one way. but...
one is to call before that loop
shell "%comspec% /c echo. > %temp%\this.txt"
and then do
shell "%comspec% /c echo $name >> %temp%\this.txt"

there you will have one machine name in each line. but what will you want to do with those names?
like, you can directly using my last code, in the middle of that loop, work with those names.
if you have some specific stuff in your mind, please be more specific. otherwise I ask you to refer to kix doc that came with the package.
like reading and writing with files is simple as calling to readline() and writeline()

cheers,

_________________________
!

download KiXnet

Top
#57930 - 2001-08-06 05:33 PM Re: Parsing Text
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
A simple way of creating an exclude list could be to create an inifile (exclude.ini) with a content like this:

[Exclude]
IPAQ02925=X
NEXTPC=X
etc.........


And then use this modified version of Lonkero's script:

code:
$exclude = Chr(10) + ReadProfileString("Exclude.ini", "Exclude", "") ; Read all key-names separated by CHR(10)
$file = "your_file"
$ = open(1,$file)
$line = readline(1)
while @error = 0
$temp = split($line,",")
$name = substr($temp[0],1,len($temp[0])-1)
If InStr($exclude, Chr(10) + $name + Chr(10)) = 0
$date = $temp[5]
;do time compare here
;and with result do something.
EndIf
$line = readline(1)
loop

Erik

Top
#57931 - 2001-08-06 07:39 PM Re: Parsing Text
Anonymous
Unregistered


Ok must be one of those days. So here is what I have. Where and how is the best way to add this exclude list to not notify these machines that they need rebooting.

Exclude.ini
*************
IPAQ1
IPAQ234
SFF3435
SRV123
*************
Parse.csv
*************
IPAQ029251=,jdoe1,John Doe1,00D0B7B4C292,8/3/2001,5:32:10
IPAQ029252=,jdoe2,John Doe2,00508BF5B653,7/25/2001,7:40:18
IPAQ029253=,jdoe3,John Doe3,000347167CFC,8/3/2001,6:37:28
IPAQ029254=,jdoe4,John Doe4,0002A575E788,8/3/2001,7:03:03
IPAQ029255=,jdoe5,John Doe5,00D0B7AB20EE,8/3/2001,6:40:57
IPAQ029256=,jdoe6,John Doe6,0002A51D7BB8,8/3/2001,6:38:37
IPAQ029257=,jdoe7,John Doe7,00508BDA9533,8/3/2001,17:49:49
IPAQ029258=,jdoe8,John Doe8,0002A51E2B21,8/3/2001,6:52:34
IPAQ029259=,jdoe9,John Doe9,0008C7636F6B,8/3/2001,5:32:09
IPAQ029250=,jdoe0,John Doe0,00D0B7B4B5E0,8/3/2001,6:58:48
****************
Parse.kix

BREAK ON
; ********** VARIABLES ************************************************

$DIF=5
$FILE = "PARSE.CSV"
$EXFILE = "exclude.ini"

; *************** OPEN FILE AND GET VARIABLES**************************


$ = open(1,$FILE)
$LINE = readline(1)
while @error = 0

$TEMP = split($line,",")
$NAME = substr($temp[0],1,len($temp[0])-1)
$DATE = $temp[4]

; *********************************CALC DATE DIF***********************

$temp2 = split($DATE,"/")
$MTH = $temp2[0]
$DY = $temp2[1]
$YR = $temp2[2]
? $MTH " =MTH"
? $DY " =DY"
? $YR " =YR"


? @MONTHNO " =MONTHNO"
? @YEAR " =YEAR"

;$DATE="12/05/1999"
;$VDate=Ltrim($DATE)
$Var_Yr = Val($YR)
$Var_Mo = Val($MTH)
$Var_Day = Val($DY)
$VDate="$Var_Mo/$Var_Day/$Var_Yr"
$Var_Mo = $Var_Mo - 1
if @Year>$Var_Yr
$Cur_Mo=@MonthNo + 11
else
$Cur_Mo=@MonthNo -1
endif
$Cur_Age= (($Cur_Mo) * 30) + @MdayNo
$Var_Age= ($Var_Mo * 30) + $Var_Day
$Dif_Age=$Cur_Age - $Var_Age


$LOG=">>> LOG.CSV"

; ***********if its been over this many days do something ************

IF $Dif_Age =>"5"
shell "%COMSPEC% /C ECHO NET SEND $NAME IT HAS BEEN MORE THAN 5 DAYS SINCE YOUR LAST REBOOT.. PLEASE REBOOT YOUR MACHINE.>> NSEND.BAT"
ENDIF

; ******************************************************************


:SKIP


$line = readline(1)
LOOP

; ***************SENDS MESSAGE **************************************


;shell "%COMSPEC% /C ECHO del nsend.bat >> NSEND.BAT"
;shell "%COMSPEC% /C NSEND.BAT"

:END

[ 06 August 2001: Message edited by: Brianb ]

[ 06 August 2001: Message edited by: Brianb ]

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 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.046 seconds in which 0.024 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