home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-19 | 3.9 KB | 148 lines | [TEXT/$Tcl] |
-
-
- set env(CRON_EXPR) { run_cron }
- set env(CRON_TICKS) 3600
-
- #
- # set cron(NAME) "month(1-12) domon(1-31) dowk(1,Mon-7,Sun) hour(1-23) minute(1-59) expr"
- #
- set cron(1) { * * * * 1-60 { feedback "CRON TASK NUMBER ONE!!!!!!" } }
- set cron(2) { * * * * 5-30,35,40 { feedback "CRON TASK NUMBER TWO!!!!!!" } }
- set cron(3) { 4-6 * * * 1-60 { feedback "CRON TASK NUMBER THREE!!!!!!" } }
- set cron(4) { * 4 * * 1-60 { feedback "CRON TASK NUMBER FOUR!!!!!!" } }
- set cron(5) { * 1-7 * * 1-60 { feedback "CRON TASK NUMBER FIVE!!!!!!" } }
- set cron(6) { * * 6 * 1-60 { feedback "CRON TASK NUMBER SIX!!!!!!" } }
-
- set MONTHS(Jan) 1
- set MONTHS(Feb) 2
- set MONTHS(Mar) 3
- set MONTHS(Apr) 4
- set MONTHS(May) 5
- set MONTHS(Jun) 6
- set MONTHS(Jul) 7
- set MONTHS(Aug) 8
- set MONTHS(Sep) 9
- set MONTHS(Oct) 10
- set MONTHS(Nov) 11
- set MONTHS(Dec) 12
-
- set DOWS(Mon) 1
- set DOWS(Tue) 2
- set DOWS(Wed) 3
- set DOWS(Thu) 4
- set DOWS(Fri) 5
- set DOWS(Sat) 6
- set DOWS(Sun) 7
-
- proc check_cron_item { list theitem } {
-
- set RESULT 0
-
- foreach mine [split $list ,] {
- #puts stdout "CHECK: '$theitem' against '$mine'"
- if "! [string compare $mine $theitem]" then {
- #puts stdout "CHECK: SUCCESS!!!! on '$mine'"
- set RESULT 1
- break
- } else {
- set DL [split "$mine" -]
- if "[llength $DL] == 2" then {
- #puts stdout "CHECK: RANGE: [lindex $DL 0] <= $theitem <= [lindex $DL 1]"
- if "$theitem >= [lindex $DL 0] && $theitem <= [lindex $DL 1]" then {
- #puts stdout "CHECK: RANGE SUCCESS!!!! on '$mine'"
- set RESULT 1
- break
- }
- }
- }
- }
-
- return $RESULT
- }
-
-
- proc run_cron { } {
- global cron MONTHS DOWS
-
- #puts stdout "NOW: [mtime [now] abbrev]"
- set thetime [mtime [now] abbrev]
- set thedow $DOWS([string trimright [lindex [lindex $thetime 0] 0] ,])
- set themon $MONTHS([lindex [lindex $thetime 0] 1])
- set thedom [string trimright [lindex [lindex $thetime 0] 2] ,]
- set theyear [lindex [lindex $thetime 0] 3]
- set thehour [lindex [split [lindex [lindex $thetime 1] 0] :] 0]
- set themin [lindex [split [lindex [lindex $thetime 1] 0] :] 1]
- set thesec [lindex [split [lindex [lindex $thetime 1] 0] :] 2]
- set theampm [lindex [lindex $thetime 1] 1]
-
- if "! [string compare PM $theampm]" then {
- if "$thehour < 12" then {
- set thehour [expr "$thehour + 12"]
- }
- }
-
- # puts stdout "$thedow $themon $thedom, $theyear $thehour:$themin:$thesec"
-
- foreach index [lsort [array names cron]] {
- #puts stdout "Checking cron task cron($index)";
- #puts stdout "## $index ## $cron($index)";
- set mon [lindex $cron($index) 0]
- set dom [lindex $cron($index) 1]
- set dow [lindex $cron($index) 2]
- set hour [lindex $cron($index) 3]
- set min [lindex $cron($index) 4]
- set task [lindex $cron($index) 5]
-
- #puts stdout " --> Mon $mon Dom $dom Dow $dow Hour $hour Min $min";
- #puts stdout " --> Task $task";
-
- if "[string compare * $mon]" then {
- #puts stdout "Have Month spec, checking '$mon' against '$themon'"
- if "! [check_cron_item $mon $themon]" then {
- #puts stdout " --> MONTH FAILED."
- continue;
- }
- }
-
- if "[string compare * $dom]" then {
- #puts stdout "Have day of month spec, checking '$dom' against '$thedom'"
- if "! [check_cron_item $dom $thedom]" then {
- #puts stdout " --> DAY OF MONTH FAILED"
- continue;
- }
- }
-
- if "[string compare * $dow]" then {
- #puts stdout "Have day of week spec, checking '$dow' against '$thedow'"
- if "! [check_cron_item $dow $thedow]" then {
- #puts stdout " --> DAY OF WEEK FAILED"
- continue;
- }
- }
-
- if "[string compare * $hour]" then {
- #puts stdout "Have hour spec, checking '$hour' against '$thehour'"
- if "! [check_cron_item $hour $thehour]" then {
- #puts stdout " --> HOUR FAILED"
- continue;
- }
- }
-
- if "[string compare * $min]" then {
- #puts stdout "Have minute spec, checking '$min' against '$themin'"
- if "! [check_cron_item $min $themin]" then {
- #puts stdout " --> MINUTE FAILED"
- continue;
- }
- }
-
- #feedback "CRON: evaluating '$task'"
- catch "$task"
- }
-
- }
-
- #run_cron
-
-
-