#38708 - 2003-04-02 04:07 PM
NAV Def files and Dates
|
DJC
Fresh Scripter
Registered: 2003-04-02
Posts: 8
Loc: UK
|
I am trying to get my script to calculate the current date compared to the current NAV def date in c:\program files\common files\Symantec shared\virusdefs\definfo.dat 20030326.002 I need to get warning if its say 30 days since the date in the file. I think i need to trim off the last 4 characters and then some how calculate the difference but i am having problems with this. Can anyone help?
_________________________
Currently on : KiXtart 95 3.60
|
Top
|
|
|
|
#38709 - 2003-04-02 04:11 PM
Re: NAV Def files and Dates
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
Use SPLIT() to separate the pathnames, use SUBSTR to separate the date field and create a reald date, then use the DATEMATH() UDF to calculate date difference. Pseudo-codecode:
$a=split('c:\program files\common files\Symantec shared\virusdefs\definfo.dat 20030326.002','\') $date=$a[ubound($a)] $date=split($date,'.')[0] $year=left($date,4) $month=substr($date,5,2) $day=right($date,2) $date=$year+'/'+$month+'/'+$day $datediff=datemath($date,@DATE)
_________________________
There are two types of vessels, submarines and targets.
|
Top
|
|
|
|
#38710 - 2003-04-02 04:23 PM
Re: NAV Def files and Dates
|
DJC
Fresh Scripter
Registered: 2003-04-02
Posts: 8
Loc: UK
|
Sorry i am using KiXtart 95 3.60 and am unable to change the version as its a corporate thing. I cant use UDF's ... any ideas?
_________________________
Currently on : KiXtart 95 3.60
|
Top
|
|
|
|
#38714 - 2003-04-03 02:41 PM
Re: NAV Def files and Dates
|
DJC
Fresh Scripter
Registered: 2003-04-02
Posts: 8
Loc: UK
|
I am quite new to the scripting lark and i have come up with the below after reading through the posts, All i need to do is test if the date in the file is older than 2 weeks. The below does not appear to work but i believe its Close, Any ideas?
code:
$CurDefDate = ReadProfileString ("c:\program files\common files\symantec shared\virusdefs\definfo.dat", "DefDates", "CurDefs" )
; The above file contains :
; [DefDates] ;CurDefs=20030326.002 ;LastDefs=20030319.002
code:
$FileYear = ltrim (SubStr($CurDefDate, 1, 4)) $FileMonth = ltrim (SubStr($CurDefDate, 5, 2)) $FileDay = ltrim (SubStr($CurDefDate, 7, 2)) $DefDates = "$FileYear$FileMonth$FileDay" $FileDate = SubStr($DefDates,1,10) ?$FileDate $NowYear = @YEAR $NowMonth = @MONTHNO $NowDate = @MDAYNO If $FileYear <> $NowYear $NowMonth = $NowMonth + (12 * ($NowYear - $FileYear)) EndIf
If $FileMonth <> $NowMonth $NowDate = $NowDate + 30 EndIf If ($NowDate - $FileDate) > 10 ? "File older than 2 weeks" Else ? "File newer than 2 weeks" EndIf
_________________________
Currently on : KiXtart 95 3.60
|
Top
|
|
|
|
#38715 - 2003-04-03 05:09 PM
Re: NAV Def files and Dates
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
You'll need to convert your dates to values instead of strings, e.g.code:
$FileYear = val(ltrim (SubStr($CurDefDate, 1, 4))) $FileMonth = val(ltrim (SubStr($CurDefDate, 5, 2))) $FileDay = val(ltrim (SubStr($CurDefDate, 7, 2)) )
[ 04. April 2003, 16:49: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.
|
Top
|
|
|
|
#38716 - 2003-04-03 09:00 PM
Re: NAV Def files and Dates
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11625
Loc: CA
|
Not sure I agree with your date logic for OLDER/NEWER files.
Here is another method of getting the date - Not very clean, but works. I'm sure Jens or Lonkero can GOLF it.
$CurDefDate = READVALUE("HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\SharedDefs","NAVCORP_70") $CurDefDate=right($CurDefDate,12) $CurDefDate=left($CurDefDate,8) $FileYear = VAL(RTRIM (SubStr($CurDefDate, 1, 4))) $FileMonth = VAL(RTRIM (SubStr($CurDefDate, 5, 2))) $FileDay = VAL(RTRIM (SubStr($CurDefDate, 7, 2))) $DefDates = "$FileYear$FileMonth$FileDay" $FileDate = VAL(SubStr($DefDates,1,8)) $NowYear = @YEAR $NowMonth = @MONTHNO $NowDate = @MDAYNO If $FileYear <> $NowYear $NowMonth = $NowMonth + (12 * ($NowYear - $FileYear)) EndIf
If $FileMonth <> $NowMonth $NowDate = $NowDate + 30 EndIf If ($NowDate - $FileDate) > 10 ? "File older than 2 weeks" Else ? "File newer than 2 weeks" ENDIF ? $FileDate
|
Top
|
|
|
|
#38720 - 2003-04-04 01:35 PM
Re: NAV Def files and Dates
|
DJC
Fresh Scripter
Registered: 2003-04-02
Posts: 8
Loc: UK
|
Typical!!!
A while after my last post i got it to work ..
It actually works as :
code:
$CurDefDate = ReadProfileString ("c:\program files\common files\symantec shared\virusdefs\definfo.dat", "DefDates", "CurDefs" ) $FileYear = val(ltrim (SubStr($CurDefDate, 1, 4))) $FileMonth = Val(ltrim (SubStr($CurDefDate, 5, 2))) $FileDay = Val(ltrim (SubStr($CurDefDate, 7, 2)) )
$NowYear = @YEAR $NowMonth = @MONTHNO $NowDay = @MDAYNO If $FileYear <> $NowYear $NowMonth = $NowMonth + (12 * ($NowYear - $FileYear)) EndIf
If $FileMonth <> $NowMonth $NowDay = $NowDay + (30 * ($Nowmonth - $Filemonth)) EndIf
If ($Nowday - $Fileday) > 25 ? "File older than 25 days"
Else ? "File newer than 25 days"
EndIf
This is the offending part that was missing :
code:
If $FileMonth <> $NowMonth $NowDay = $NowDay + (30 * ($Nowmonth - $Filemonth))
Once again Thanks for all your help ..
_________________________
Currently on : KiXtart 95 3.60
|
Top
|
|
|
|
#38721 - 2003-04-04 02:01 PM
Re: NAV Def files and Dates
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
DJC,
I can't promise that this will work with 3.60 (as I don't have a copy and won't download) but despite my best knowledge the below WILL work (at any day as these date algorithms are always valid)
break on
global $rd_day,$rd_month,$rd_year,$rd_internal
$CurDefDate = readprofilestring("c:\program files\common files\symantec shared\virusdefs\definfo.dat", "DefDates", "CurDefs" )
$rd_year = val(substr($CurDefDate, 1, 4)) $rd_month = val(substr($CurDefDate, 5, 2)) $rd_day = val(substr($CurDefDate, 7, 2))
gosub "intdate"
$Def_Int = $rd_internal
$rd_year = @year $rd_month = @monthno $rd_day = @mdayno
gosub "intdate"
$Def_Age = $rd_internal - $Def_Int
"Virus definitions are " + $Def_Age + " Day(s) old"
get $key
exit 1
:intdate ;this is normally CALLed but for clarity I made it a SUB
; ; intdate.kix ; Library routine to convert a date from Calendar to internal format. ; ; The algorithm used here is taken directly from the following document: ; http://www.capecod.net/~pbaum/date/date0.htm ; ; Variables passed: ; rd_day IN Day of month (0-31) ; rd_month IN Month of year (1-12) ; rd_year IN Full year ; rd_internal OUT Internal representation ; ; Amendment history: ; Version 1.0 21 June 2000 Richard Howarth ;
dim $MyYear,$MyMonth $MyYear = $rd_year $MyMonth = $rd_month if $MyMonth < 3 $MyMonth = $MyMonth + 12 $MyYear = $MyYear - 1 endif $rd_internal = $rd_day + ( 153 * $MyMonth - 457 ) / 5 + 365 * $MyYear + $MyYear / 4 - $MyYear / 100 + $MyYear / 400 - 306
return
($Def_Age is the days between the .dat date and today)
hth
_________________________
|
Top
|
|
|
|
#38725 - 2003-04-04 10:25 PM
Re: NAV Def files and Dates
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 202 anonymous users online.
|
|
|