#!/usr/bin/perl # Time-stamp: "2005-08-19 01:37:15 ADT" sburke@cpan.org #desc{ diffs the active crontab against a given file } use strict; my $x; unless(@ARGV == 1 and defined($x = $ARGV[0]) and length $x and -e $x and -f _ ) { require File::Basename; die "Usage: ", File::Basename::basename($0), " filespec\n"; } my(@content) = (`crontab -l 2>&1`); # Get the current crontab print("[No crontab?]\n"), exit() unless @content; print("[No crontab.]\n"), exit() if @content == 1 and $content[0] =~ m<^no crontab>si; splice @content, 0, 3 # remove the hoohah that might be there. if @content >= 3 and $content[0] =~ m<^# DO NOT EDIT THIS FILE>s and $content[1] =~ m<^# \(.* installed on>s and $content[2] =~ m<^# \(Cron version>s ; # Make the temp file: my $temp = "/tmp/diff_crontab_$$"; open(OUT, ">$temp") or die "Can't write-open $temp: $!"; print OUT @content; close(OUT); sleep 0; my(@diffy) = `diff $temp $x`; # So output goes: # < line in existing crontab, missing in new crontab # > line in new crontab, missing in existing crontab sleep 0; unlink $temp; # nix temp file print @diffy; print "(No differences)\n" unless @diffy; exit;