home *** CD-ROM | disk | FTP | other *** search
- #!/bin/vtcl
- # ---------------------------------------------------------------------
- # Copyright 1994 by SCO, Inc.
- # Permission to use, copy, modify, distribute, and sell this software
- # and its documentation for any purpose is hereby granted without fee,
- # provided that the above copyright notice appear in all copies and that
- # both that copyright notice and this permission notice appear in
- # supporting documentation, and that the name of SCO not be used in
- # advertising or publicity pertaining to distribution of the software
- # without specific, written prior permission. SCO makes no
- # representations about the suitability of this software for any
- # purpose. It is provided "as is" without express or implied warranty.
- # ---------------------------------------------------------------------
- #
- # Demo : cron.tcl
- # Description : Example used on a SCO tech journal article.
- # Comments : This demo allows the user to view the contents of
- # a crontabs file. NEED root permission.
- # Highlights - file I/O, use of rowcolumn widget, keyed list.
- #
- proc GetCronRecordList {filename} {
- set fd [open $filename r]
- while { ! [eof $fd] } {
- if {[gets $fd record] > 0 } {
- # We'll skip commented records
- if { [cindex $record 0] != "#"} {
- lappend cronRecordList $record
- }
- }
- }
- close $fd
- return $cronRecordList
- }
-
- proc ParseCronRec {record} {
- set itemList [split $record "\t " ]
- set scheduleFields [lrange $itemList 0 4]
- set commandField [lrange $itemList 5 end]
- keylset parsedCronRec MINUTE [lindex $scheduleFields 0]
- keylset parsedCronRec HOUR [lindex $scheduleFields 1]
- keylset parsedCronRec MONTHDAY [lindex $scheduleFields 2]
- keylset parsedCronRec YEAR [lindex $scheduleFields 3]
- keylset parsedCronRec WEEKDAY [lindex $scheduleFields 4]
- keylset parsedCronRec COMMAND $commandField
- return $parsedCronRec
- }
-
- proc ShowDetailsCB {cbs} {
- set parent [keylget cbs dialog]
- set dlog [VtFormDialog $parent.dlog \
- -title "Cron Record Details" \
- -okCallback WxEndFormCB \
- ]
- set leftColumnW [VtRowColumn $dlog.left \
- ]
- set rightColumnW [VtRowColumn $dlog.right \
- -leftSide $leftColumnW \
- -alignTop $leftColumnW \
- -leftOffset 0 \
- ]
- set labelList [list Minute: Hour: "Day in Month:" Year: "Week Day:" ]
- foreach label $labelList {
- VtLabel $leftColumnW.$label \
- -label $label \
- -labelRight
- }
- set fieldKeyList {MINUTE HOUR MONTHDAY YEAR WEEKDAY}
- set record [keylget cbs selectedItemList]
- set cronList [ParseCronRec [lvarpop record]]
- foreach fieldKey $fieldKeyList {
- VtLabel $rightColumnW.$fieldKey \
- -label [keylget cronList $fieldKey] \
- -labelLeft
- }
-
- VtText $dlog.command \
- -below $leftColumnW \
- -value [keylget cronList COMMAND] \
- -columns 40 \
- -horizontalScrollBar True \
- -bottomSide FORM
-
- VtShow $dlog
-
-
-
- }
-
- proc BuildMainDialog {dialog filename cronRecords} {
- set titleLabelW [VtLabel $dialog.title \
- -label "Cron entries in $filename" \
- ]
- set cronListW [VtList $dialog.cronList \
- -itemList $cronRecords \
- -rightSide FORM \
- -bottomSide FORM \
- -callback ShowDetailsCB \
- ]
- }
-
- proc CloseProgramCB {cbs} {
- VtClose; exit 0
- }
- set appShell [VtOpen CronBrowser]
- set mainDialog [VtFormDialog $appShell.mainD \
- -title "Cron Browser Program" \
- -okLabel Exit \
- -okCallback CloseProgramCB \
- -wmCloseCallback CloseProgramCB \
- ]
-
- set filename /usr/spool/cron/crontabs/root
-
- if { ! [file readable $filename] } {
- set errDlog [VtErrorDialog $mainDialog.errDlog \
- -message "You must have permission to read:\n$filename \
- \n\n OR\n \
- \nsimply rename the crontab file in this \
- \nprogram to one that you can read." \
- -ok \
- -okCallback CloseProgramCB \
- ]
- VtShow $errDlog
- # Need to put a main loop here since the program shouldn't
- # go on from here and we need to enter an event-loop in order
- # 1) prevent the rest of the code from getting executed, and
- # 2) to get the CloseProgramCB called.
- #
- VtMainLoop
- }
- set cronRecords [GetCronRecordList $filename]
-
- BuildMainDialog $mainDialog $filename $cronRecords
- VtShow $mainDialog
- VtMainLoop
-
-