Schedule a procedure to run once a day
ns_schedule_daily ?-thread? ?-once? hour minute {script | procname ?args?}
ns_schedule_daily runs the specified Tcl script or procedure (procname) once a day at the time specified by hour and minute. The hour can be from 0 to 23, and the minute can be from 0 to 59.
Specify -thread if you want a thread created to run the procedure. This will allow the scheduler to continue with other scheduled procedures. Specifying -thread is appropriate in situations where the script will not return immediately, such as when the script performs network activity.
Specify -once if you want the script to run only one time. The default is that the script will be re-scheduled after each time it is run.
ns_schedule_daily returns an id number for the scheduled procedure that is needed to stop the scheduled procedure with ns_unschedule_proc.
This example defines a script called rolllog
that uses ns_accesslog to roll the access log to a file with an extension containing the current date. The ns_schedule_daily function is used to execute the rolllog
script on a daily basis.
# Script to roll and rcp log file to host "grinder" proc rolllog {} { set suffix [ns_strftime "%y-%m-%d"] set new [ns_accesslog file].$suffix ns_accesslog roll $new exec rcp $new grinder:/logs/[file tail $new] } # Schedule "rolllog" to run at 3:30 am each morning ns_schedule_daily -thread 3 30 rolllog