Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perpetual Capture and Autostart and stop on specific day of week. 1

Status
Not open for further replies.

dkmansion

Technical User
Feb 24, 2005
32
US
Hello all, I have a PC serial conencted to capture data on our paging system. Only the standard Startup script is running.

Each Monday morning we have a user manually stop the capture that is taking place and restart the capture. Unfortunately due to human error I find that periodically there is no capture taking place.

I have not done any ASPECT scripting so I don't even know where to start. I would like to accomplish the following:

1. Stop the File capture Weekly Sunday night at 23:59:59 and restart it Monday morning 00:00:00.
2. Periodically check to makesure a capture is active if not restart the capture so I don't loose any data capture.

Weekly we dump the capture into a database for tracking of pages sent. This is used in a Hospital.

Thanks in advance for any direction there may be...

Donald M
 
SO I did more searching and have code to start and stop the capture at the day change. Sunday AM just before the midnight day change.
Code:
proc main
   integer LeapYear           ; Stores state of leap year.
   integer DayYear, DayWeek   ; Day of year and day of week.
   string WeekDay, Leap       ; Strings for day and leap state.
 
   ; Get the day of the week, day of the year, and state of leap
   ; year. Leap year is a 0 or 1 value.
   ltimemisc $LTIME DayWeek DayYear LeapYear
   weekdaystr DayWeek WeekDay ; Get day of week in string format.

   if DayWeek == 1               ; See if it's a leap year and if so,
      waituntil "23:59:30"            
      Capture off
      waituntil "23:59:31"
      Capture on
   endif

endproc
What I have left is a periodic check to make sure that a capture is happenning. I would like to encapsulate the two so that there is always a capture going on until the OFF at 23:59:30. Either the periodic check or the wait until 23:59:31 would reactivate the capture.

Does this sond like something that is possible? Can teh capture status be monitored?

Donald M
 
There is not really a periodic way to check that the capture is still occurring since the script will be paused in the waituntil command until the specified time. What you could do is use a when $CAPTURE command to monitor the status of that system variable and call a procedure whenever that value changes. You would want to make sure the value of $CAPTURE is 0, indicating that no capture is active and can then turn it back on.

You would also need some logic to check to see if the capture is turned off due to the specified time being reached. You may be able to due this by eliminating these lines:

waituntil "23:59:31"
Capture on

and letting your when $CAPTURE line kick in automatically to turn the capture file back on.

There are two other things to keep in mind. The first is that nothing being captured is saved if Procomm crashes, the PC is rebooted, etc. while the capture file is open. The second is that closing and reopening a capture file will cause the current screen to be written twice to the capture file. To eliminate that, you can issue the clear command before reopening the capture file. This will give you about a screen's worth of blank lines, but at least no duplicated data.

 
Thanks Knob,

Should I wrap them together like this?
Code:
if $CAPTURE == 0
    capture on

    if DayWeek == 1
      waituntil "23:59:30"
      capture off
      clear
    endif

endif

I also wrapped the code in
Code:
while 1
yield
(capture code here)
endwhile

To save from accidental user closure of Procomm.

Can you suggest elements (¿system Variable?) to look into to trigger when procomm in closing, so I can send capture off?


Donald M
 
Hi Knob,

I have got the code almost where I need it but there is a problem. At the minute change over from 59 seconds to the new minute two captures are created not one. Basically it captures then closes then captures again. I only have ONE capture off in the code. What do you think might be happening?
Code:
proc main

integer LeapYear
integer DayYear, DayWeek
string WeekDay
string sDay, sHour, sMin, sSec, sMonth, sYear
integer iDay, iHour, iMin, iSec, iMonth, iYear 

while 1
yield 

GetNewTime:
strset WeekDay 0 0 255
strset sDay 0 0 255
strset sHour 0 0 255
strset sMin 0 0 255
strset sSec 0 0 255
strset sMonth 0 0 255
strset sYear 0 0 255

	; Get the day of the week, day of the year, and state of leap year.
	ltimemisc $LTIME DayWeek DayYear LeapYear
		weekdaystr DayWeek WeekDay ; Get day of week in string format.

	ltimeints $LTIME iYear iMonth iDay iHour iMin iSec
		numtostr iHour sHour
		numtostr iMin sMin
		numtostr iSec sSec

CaptureAuto: 
if $CAPTURE == 0
    capture on
endif

CheckDayAndTime:
    if DayWeek == 6
    	if iHour = 17
     		if iMin = 20
          		if iSec >= 57
          		     waituntil "17:20:59"
               		     capture off
      			     clear
      			     pause 2

          		endif
          	goto getnewtime
       		endif
       	goto getnewtime
	endif
   goto getnewtime
   endif

goto getnewtime
    
endwhile
endproc

Some of the goto statements might be overkill but I'm kinda new to this .. Thanks in advance.

Donald M
 
Does it look like the two captures are occuring in the same minute? You might try changing the pause 2 to a pause 60 so that the script waits a minute before turning the capture file back on.

 
Yes they were happenning at the same time. Basically within milliseconds. Pausing for 60 seconds made it worse. It actually captured 5 or six and then kept doing it every minute after. I made a change to pause 1 second and then I changed the time evaluation in the if statements at the CheckDayAndTime label to == for hour and minute.

I've added labels and comments. Here is the code if anyone would like to use it.

Code:
proc main
;script by Donald Mansion 2007 dkmansion at gmail.com
;define variables for use throught the script
integer iLeapYear
integer iDayYear, iDayWeek
string sWeekDay
string sDay, sHour, sMin, sSec, sMonth, sYear
integer iDay, iHour, iMin, iSec, iMonth, iYear 

;While statement used to give warningif someone tries to close ProComm.
while 1
yield 

		;update time
GetNewTime:
strset sWeekDay 0 0 255  ;erase each string when new time is obtained
strset sDay 0 0 255
strset sHour 0 0 255
strset sMin 0 0 255
strset sSec 0 0 255
strset sMonth 0 0 255
strset sYear 0 0 255

	
ltimemisc $LTIME iDayWeek iDayYear iLeapYear	; Get the day of the week, day of the year, and state of leap year.
weekdaystr iDayWeek sWeekDay 	; Get day of week in string format.

ltimeints $LTIME iYear iMonth iDay iHour iMin iSec	;get the year, hour, day, min, sec from time update.
	;convert time integers to strings for evaluation in CheckDayAndTime
	numtostr iHour sHour
	numtostr iMin sMin
	numtostr iSec sSec

;Make sure there is ALWAYS a capture happening.
CaptureAuto: 
if $CAPTURE == 0
    capture on
endif

;Check the current time against the specific day and hour we want to reset the capture.
CheckDayAndTime:
    if iDayWeek == 1		;DayOfWeek Sunday through Saturday (1 - 7)
    	if iHour == 23		;Hour on clock NOW (24 Hour Clock)
     		if iMin == 59	;Minute on clock NOW
          		if iSec >= 57		;if 57 or more seconds is on the clock (Sunday 11:59:57/58/59 PM) wait until time below
          		     waituntil "23:59:59"
               		     capture off
      			     clear
      			     pause 1
           		endif
       		endif
	endif
   endif
   
pause 1		;wait a second before getting new time.
goto getnewtime		;after each pass at CheckDayAndTime go get the new time cause it doesn't stand still.
    
endwhile
endproc

The code only sets one capture when the time specified was reached and didn't do a new capture each minute like the other code did. I have added it to my live capture server and will see if it all is Ok after midnight tonight.

Thanks for the help

Donald M
 
You could also hold the time/date of the last new capture, and compare against that ( say 09/11/2007 23:59:59 ) and wait until that time plus 24 hours ( or a week in your case), then update the last capture variable.

So the next time it hit the capture code, it's looking for a different date/time.
 
Thanks for the suggestions kodr. I'll look into how that would work. This is my first "big" (not three lines of code) script in ASPECT language.

The code worked perfectly last night. One single capture at midnight was restarted. Thanks again to knob, and I appreciate kodr for the alternate example.



Donald M
 
UPDATE: So Ive been running this code for a month ad a half and it's working perfectly. Every Monday at 12:00 AM the capture stops then restarts as I want it too. Next I'll work to have it email up a status message when it restarts.

Donald M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top