]> pere.pagekite.me Git - homepage.git/blob - linux/cron-summary
Generated.
[homepage.git] / linux / cron-summary
1 #!/store/bin/perl
2
3 ##
4 # Fetches all crontabs on the hosts specified on the command line
5 # and presents them sorted on user, machine and time.
6 #
7 # @author Petter Reinholdtsen <pere@td.org.uit.no>
8 # @params host1 [host2 ...]
9 # @made 1996-07-27
10 # @version $Id: cron-summary,v 1.1 2003/06/02 13:01:37 pere Exp $
11 sub about {}
12
13 $crondir = "/var/spool/cron/crontabs";
14 $rsh = $ENV{RSH} || 'rsh';
15
16 @hosts = @ARGV;
17
18 foreach $host (@hosts) {
19 @users = &get_cronusers($host);
20 print "Users at $host: ".join(",", @users)."\n";
21 foreach $user (@users) {
22 &parse_crontab($host, $user);
23 }
24 }
25
26 &show_cronsummary();
27
28 ##
29 # Fetches the contents of $crondir from $host and returns all users as
30 # an array
31 #
32 # @params $host
33 # @return @users
34 sub get_cronusers {
35 local($host) = @_;
36 local($res) = `$rsh $host echo $crondir/\\*`;
37 $res =~ s%$crondir/%%g;
38 local(@users) = split(/\s+/, $res);
39 return @users;
40 }
41
42 ##
43 # Fetches the crontab-file for $user from $host and stores the info in
44 # @cron.
45 # @params $host, $user
46 # @return "" on failures and "1" on success.
47 sub parse_crontab {
48 local($host, $user) = @_;
49 open(CRONTAB, "rsh $host cat $crondir/$user|") ||
50 die "Unable to open crontab on $host for $user";
51 while (<CRONTAB>) {
52 next if (/^\#/);
53 ($min, $hour, $dom, $moy, $daw, $command) =
54 m/^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+)$/;
55 push(@cron,join(":", $user, $host, $hour, $min, $dom, $moy, $daw, $command));
56 }
57 close(CRONTAB);
58 return "1";
59 }
60
61 ##
62 # Prints the crontab summary based on the info in @cron
63 sub show_cronsummary {
64 local($lastuser, $lasthost);
65 foreach $line (sort @cron) {
66
67 ($user) = m/^(.+):/;
68 ($user, $host, $hour, $min, $dom, $moy, $daw, @command) =
69 split(/:/, $line);
70 if ($user ne $lastuser) {
71 print "\nUser: $user\n";
72 $lasthost = "";
73 }
74 print " Host: $host\n" if ($host ne $lasthost);
75 $lastuser = $user;
76 $lasthost = $host;
77
78 print " $line\n";
79 }
80 }