news.utdallas.edu!wupost!darwin.sura.net!sgiblab!munnari.oz.au!sol.deakin.OZ.AU!mimas.cc.deakin.OZ.AU!not-for-mail Tue Mar 9 22:07:43 CST 1993 Article: 1478 of comp.lang.perl Xref: feenix.metronet.com comp.lang.perl:1478 Path: feenix.metronet.com!news.utdallas.edu!wupost!darwin.sura.net!sgiblab!munnari.oz.au!sol.deakin.OZ.AU!mimas.cc.deakin.OZ.AU!not-for-mail From: tim@deakin.OZ.AU (Tim Cook) Newsgroups: comp.lang.perl #Subject: SOURCE: cronsort - Show crontab entries sorted by class and/or time Date: 10 Mar 1993 09:03:31 +1000 Organization: Deakin University Lines: 208 Message-ID: <1nj7o3INNl1u@mimas.cc.deakin.OZ.AU> NNTP-Posting-Host: mimas.cc.deakin.oz.au Have a look at the top of the source to see what this can do, but if you want to see its best feature, try $ cronsort -a | more I just discovered that a "cronsort" was posted to comp.sources.misc in 1988. Written in C of course, and with somewhat fewer features, IMHO. #!/bin/sh # This is a shell archive (shar 3.32) # made 03/09/1993 23:00 UTC by tim # # existing files WILL be overwritten # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 5218 -r-xr-x--- cronsort # if touch 2>&1 | fgrep 'amc' > /dev/null then TOUCH=touch else TOUCH=true fi # ============= cronsort ============== echo "x - extracting cronsort (Text)" sed 's/^X//' << 'SHAR_EOF' > cronsort && X#!/usr/local/bin/perl X# cronsort - Show particular entries from a crontab, sorted X# X# $Id: cronsort,v 1.3 1993/03/09 23:00:06 tim Exp $ X# $Source: /tmp_mnt/src/config/var/spool/cron/crontabs/root/RCS/cronsort,v $ X# X# SYNOPSIS X# cronsort [-y|-m|-w|-d|-r|-o|-a] [-n] [crontab] X# X# DESCRIPTION X# -y Shows all entries executed once per year. X# -m Shows all entries executed once per month. X# -w Shows all entries executed once per week. X# -d Shows all entries executed once per day, more than one X# day per week. X# -r (Regular) shows all entries executed more than once. X# every day. X# -o (Other) shows all entries that do not match any of the X# above criteria (yes it is possible). X# -a Shows all of the above, grouped into the above X# classifications, plus any comments at the start of the X# crontab. X# -n If specified, no comments will be output. X# [crontab] X# The name of a crontab file. Default is standard X# input. X X Xrequire 'getopts.pl'; X X X############################################################################## X# main - For want of a better word X# X X&Getopts ('ymwdroan'); X X$prog = substr ($0, rindex ($0, '/') + 1); X Xif (length ("$opt_y$opt_m$opt_w$opt_d$opt_r$opt_o$opt_a") != 1) { X die "usage: $prog [-y|-m|-w|-d|-r|-o|-a] [-n] [crontab]\n"; } X Xif ($opt_a && ! $opt_n) { X while (<>) { X last if (! /^#/); X print; } X if (! /^\s*$/) { X chop; X push (@entries, $_); } X } X Xwhile (<>) { X next if (/^#/); X next if (/^\s*$/); X chop; X push (@entries, $_); X } X Xif ($opt_y) { X &cronsort ('y', @entries); } Xelsif ($opt_m) { X &cronsort ('m', @entries); } Xelsif ($opt_w) { X &cronsort ('w', @entries); } Xelsif ($opt_d) { X &cronsort ('d', @entries); } Xelsif ($opt_r) { X &cronsort ('r', @entries); } Xelsif ($opt_o) { X &cronsort ('o', @entries); } Xelsif ($opt_a) { X foreach $type ('Regular', 'Daily', 'Weekly', 'Monthly', 'Yearly', X 'Other') { X if (! $opt_n) { X print ("####################\n", X "# ", $type, "\n", X "####################\n"); } X $type = substr ($type, 0, 1); X $type =~ tr/[A-Z]/[a-z]/; X &cronsort ($type, @entries); X } X } X Xexit (1); X X X############################################################## X# cronsort - Sort and output entries of specified type X# Xsub cronsort { X local ($type) = shift (@_); X local (@entries) = @_; X X local ($_); X local (@fields); X local (@output); X local ($entry); X local ($dummy, $cron); X X local ($any_minute, $any_hour, $any_day, $any_month, $any_weekday); X local ($specific_minute, $specific_hour, $specific_day, X $specific_month, $specific_weekday); X local ($many_minutes, $many_hours, $many_weekdays); X local ($yearly, $monthly, $weekly, $daily, $regular, $other); X X foreach $_ (@entries) { X @fields = split; X X $any_minute = ($fields[0] eq '*'); X $any_hour = ($fields[1] eq '*'); X $any_day = ($fields[2] eq '*'); X $any_month = ($fields[3] eq '*'); X $any_weekday = ($fields[4] eq '*'); X X $specific_minute = ($fields[0] =~ /^[0-9]+$/); X $specific_hour = ($fields[1] =~ /^[0-9]+$/); X $specific_day = ($fields[2] =~ /^[0-9]+$/); X $specific_month = ($fields[3] =~ /^[0-9]+$/); X $specific_weekday = ($fields[4] =~ /^[0-9]+$/); X X $many_minutes = ! $specific_minute; X $many_hours = ! $specific_hour; X $many_weekdays = ! $specific_weekday; X X $yearly = ($specific_minute && $specific_hour && $specific_day && X $specific_month && $any_weekday); X $monthly = ($specific_minute && $specific_hour && $specific_day && X $any_month && $any_weekday); X $weekly = ($specific_minute && $specific_hour && $any_day && X $any_month && $specific_weekday); X $daily = ($specific_minute && $specific_hour && $any_day && X $any_month && $many_weekdays); X $regular = ($any_weekday && $any_month && $any_day && X ($many_minutes || $many_hours)); X X $other = ! $yearly && ! $monthly && ! $weekly && ! $daily && ! X $regular; X X if ($yearly && ($type eq 'y')) { X push (@output, sprintf ('%03d%03d%03d%03d:%s', $fields[3], X $fields[2], $fields[1], $fields[0], $_)); X } X elsif ($monthly && ($type eq 'm')) { X push (@output, sprintf ('%03d%03d%03d:%s', $fields[2], X $fields[1], $fields[0], $_)); X } X elsif ($weekly && ($type eq 'w')) { X push (@output, sprintf ('%03d%03d%03d:%s', $fields[4], X $fields[1], $fields[0], $_)); X } X elsif ($daily && ($type eq 'd')) { X push (@output, sprintf ('%03d%03d%20s:%s', $fields[1], X $fields[0], $fields[4], $_)); X } X elsif ($regular && ($type eq 'r')) { X push (@output, sprintf ('%03d%1d%03d:%s', $fields[1], X $specific_minute, $fields[0], $_)); X } X elsif ($other && ($type eq 'o')) { X push (@output, sprintf ('%20s|%20s|%20s|%20s|%20s:%s', X $fields[4], $fields[3], $fields[2], $fields[1], X $fields[0], $_)); X } X } X X @output = sort (@output); X X foreach $entry (@output) { X ($dummy, $cron) = split (':', $entry, 2); X print ($cron, "\n"); X } X } SHAR_EOF $TOUCH -am 0310090093 cronsort && chmod 0550 cronsort || echo "restore of cronsort failed" set `wc -c cronsort`;Wc_c=$1 if test "$Wc_c" != "5218"; then echo original size 5218, current size $Wc_c fi exit 0