Page 1 of 1 1
Topic Options
#136836 - 2005-03-31 04:03 AM Check Date in Text File
ClientMaster Offline
Fresh Scripter

Registered: 2005-01-19
Posts: 46
Loc: Tokyo, Japan
I was wondering if I could get some help.
I have several kix scripts running on login.
I have each script logging a date file of when it last ran to a text file on the C Drive.
I don`t want to run the scripts everytime a user logs on.
I want the script to check the text files for the corresponding script and check the date inside, if the date is more that 7 days old, run the script again. If less that 7 days, don`t run the script.
Would anyone be able to help?

Top
#136837 - 2005-03-31 04:13 AM Re: Check Date in Text File
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Please post questions like this that don't include script code to General or Starters forum.

Take a look at this post and see if that helps you do what you're looking to do or not.

running a script every 45 days

If that meets your needs you could modify to 7 days instead of 45.

Top
#136838 - 2005-03-31 05:40 AM Re: Check Date in Text File
ClientMaster Offline
Fresh Scripter

Registered: 2005-01-19
Posts: 46
Loc: Tokyo, Japan
Sorry. Wasn`t sure where to put it...
I took a look at the 45 days stuff.
Everyone tended towards writing to the registry.
I need to stay away from the registry.
That is why I have the current scripts logging date stamp to local files.
I am really new to this stuff and appreciate everyone`s help.
_________________________
How can you know good, unless you experience bad.

Top
#136839 - 2005-03-31 05:44 AM Re: Check Date in Text File
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Write to an .INI file and use any of the date calculation UDFs for the date math.
_________________________
There are two types of vessels, submarines and targets.

Top
#136840 - 2005-03-31 06:16 AM Re: Check Date in Text File
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Well I see you show you're in Japan. Is the OS in Japanese or English or ??

Can you please provide an example output of the file you currently have and maybe the code you're currently using as well.

I'm sure we can come up with solutions, but to stay close to what you're doing we need to see it.

Thanks.

Top
#136841 - 2005-03-31 07:13 AM Re: Check Date in Text File
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Here is an example of reading the date from the .ini file and acting on it.
Give this a try and let us know how it goes please.

Example Output

  • Applications script last ran on 2005/03/05 which was 25 days ago
    It is now time to run the Applications script again

    The Hardware script does not need to be run at this time.

    Security script last ran on 2005/03/15 which was 15 days ago
    It is now time to run the Security script again

    Software script last ran on 2005/03/08 which was 22 days ago
    It is now time to run the Software script again


Here is the contents of the test file lastrun.ini

[scripts]
Applications=2005/03/05
Hardware=2005/03/25
Security=2005/03/15
Software=2005/03/08



Break On
Dim $SO,$Pause
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('WrapAtEOL','On')


Dim $Applications, $Hardware, $Security, $Software
Dim $LastRunApplications, $LastRunHardware, $LastRunSecurity, $LastRunSoftware
$Applications = ReadProfileString (@ScriptDir+'\'+'lastrun.ini', 'scripts', 'Applications')
$Hardware = ReadProfileString (@ScriptDir+'\'+'lastrun.ini', 'scripts', 'Hardware')
$Security = ReadProfileString (@ScriptDir+'\'+'lastrun.ini', 'scripts', 'Security')
$Software = ReadProfileString (@ScriptDir+'\'+'lastrun.ini', 'scripts', 'Software')


$LastRunApplications = DateCalc(@DATE,$Applications)
$LastRunHardware = DateCalc(@DATE,$Hardware)
$LastRunSecurity = DateCalc(@DATE,$Security)
$LastRunSoftware = DateCalc(@DATE,$Software)


If $LastRunApplications > 7
? 'Applications script last ran on '+$Applications+' which was '+$LastRunApplications+' days ago'
? 'It is now time to run the Applications script again' ?
; Run the applications script and update the lastrun.ini
Else
? 'The applications script does not need to be run at this time.' ?
EndIf


If $LastRunHardware > 7
? 'Hardware script last ran on '+$hardware+' which was '+$LastRunhardware+' days ago'
? 'It is now time to run the Hardware script again' ?
; Run the applications script and update the lastrun.ini
Else
? 'The Hardware script does not need to be run at this time.' ?
EndIf


If $LastRunSecurity > 7
? 'Security script last ran on '+$security+' which was '+$LastRunSecurity+' days ago'
? 'It is now time to run the Security script again' ?
; Run the security script and update the lastrun.ini
Else
? 'The Security script does not need to be run at this time.' ?
EndIf


If $LastRunsoftware > 7
? 'Software script last ran on '+$software+' which was '+$LastRunSoftware+' days ago'
? 'It is now time to run the Software script again' ?
; Run the Software script and update the lastrun.ini
Else
? 'The Software script does not need to be run at this time.' ?
EndIf


Function DateCalc($date1, $DateOrMod, optional $SingleDigit)
Dim $_intDate1, $_intYear1, $_intMonth1, $_intDay1
Dim $_intDate2, $_intYear2, $_intMonth2, $_intDay2
$date1 = Split($date1,'/')
If UBound($date1) <> 2
Exit 1
EndIf
$_intYear1 = Val($date1[0])
$_intMonth1 = Val($date1[1])
$_intDay1 = Val($date1[2])
If $_intMonth1 < 3
$_intMonth1 = $_intMonth1 + 12
$_intYear1 = $_intYear1 - 1
EndIf
$_intDate1 = $_intDay1 + ( 153 * $_intMonth1 - 457 ) / 5 + 365 * $_intYear1 +
$_intYear1 / 4 - $_intYear1 / 100 + $_intYear1 / 400 - 306
Select
Case VarType($DateOrMod) = 3
$_intDate2 = $_intDate1 + $DateOrMod
If InStr($_intDate2,'-') $_intDate2 = Val(SubStr($_intDate2,2,len($_intDate2)-1)) EndIf
$_intYear2 = ( 100 * ( ( ( 100*($_intDate2+306)-25)/3652425)
- ( ((100*($_intDate2+306)-25)/3652425)/4)
) + (100*($_intDate2+306)-25)
) / 36525
$_intMonth2 = ( 5 * ( ( ( 100*($_intDate2+306)-25)/3652425)
- ( ((100*($_intDate2+306)-25)/3652425)/4)
+ ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4
) + 456
) / 153
$_intDay2 = ( ( ( 100*($_intDate2+306)-25)/3652425)
- ( ((100*($_intDate2+306)-25)/3652425)/4)
+ ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4
) - ( 153 * $_intMonth2 - 457
) / 5
If $_intMonth2 > 12 $_intYear2 = $_intYear2 + 1 $_intMonth2 = $_intMonth2 - 12 EndIf
If Not $SingleDigit
If Len($_intYear2 ) < 4
$_ = Execute("for $i=1 to 4-Len($$_intYear2) $$_intYear2 = '0' + $$_intYear2
next"
)
EndIf
$_intMonth2 = Right("0" + $_intMonth2,2)
$_intDay2 = Right("0" + $_intDay2,2)
EndIf
$DateCalc = ''+$_intYear2+'/'+$_intMonth2+'/'+$_intDay2
Case VarType($DateOrMod) = 8
$DateOrMod = Split($DateOrMod,'/')
If UBound($DateOrMod) <> 2
Exit 1
EndIf
$_intYear2 = Val($DateOrMod[0])
$_intMonth2 = Val($DateOrMod[1])
$_intDay2 = Val($DateOrMod[2])
If $_intMonth2 < 3
$_intMonth2 = $_intMonth2 + 12
$_intYear2 = $_intYear2 - 1
EndIf
$_intDate2 = $_intDay2 + ( 153 * $_intMonth2 - 457 ) / 5 + 365 * $_intYear2 +
$_intYear2 / 4 - $_intYear2 / 100 + $_intYear2 / 400 - 306
$DateCalc = $_intDate1 - $_intDate2
;comment the next line If you wish to return negative results also !!!
If InStr($DateCalc,'-') $DateCalc = Val(SubStr($DateCalc,2,Len($DateCalc)-1)) EndIf
Case 1
Exit 1
EndSelect
EndFunction


Top
#136842 - 2005-03-31 09:10 AM Re: Check Date in Text File
ClientMaster Offline
Fresh Scripter

Registered: 2005-01-19
Posts: 46
Loc: Tokyo, Japan
Thank you very much...

I modified it to read the lastrun.ini from c drive.
However, it doesn`t update the file once the script has run...
any ideas?
_________________________
How can you know good, unless you experience bad.

Top
#136843 - 2005-03-31 10:24 AM Re: Check Date in Text File
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
I did not code it to update the file, you need to do that.

This was just an example since I don't have or know your real code or scripts you are calling.

Basically once you call a script/function to run that you want to update, then update it with
WriteProfileString ("file name", "section", "key", "string")

There are examples in the manual.

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 764 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 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