Net-NIS-Listgroup

 view release on metacpan or  search on metacpan

make_cron  view on Meta::CPAN


my $RSH = 'ssh';

sub Usage {
    my $error = shift;
    print STDERR "Error: $error\n" if $error;

    print STDERR <<EOF;
$0 [ -vda ] [ -h host ] [ -T host ][ -u user ] [ -t time ] [ -u user ] file ...

Take comments from the given list of files and installs cron jobs.
Will attempt to install on all machines named in the comments.
In the comment format description below, netgroup_expression may be of the
form: \@netgroup_name or (\@netgroup_name -exclude_hostname1 -exclude_hostnameN)

  #CRON: host        host_name  NIGHTLY  order_in_nightly_run
  #CRON: host        host_name           cron_arguments           
  #CRON: netgroup    netgroup_expression NIGHTLY  order_in_nightly_run]
  #CRON: netgroup    netgroup_expression cron_arguments
  #CRON: user        username

$0 flags, in detail:

  -v        show cronjobs as installing
  -d        do not install; show only
  -a        make sure all jobs have admutil controls for email, etc.
  -h host   only install on host [host]
  -t time   the time the nightly batch run should start
  -u user   specify user to install as if running as root
  -T host   override all hosts to host for testing

Copyright (C) 2003 Chelsea Networks, under the GNU GPL.
make_cron comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
welcome to redistribute it under certain conditions; see the COPYING file 
for details.

EOF

    exit 255;
}

my %opts;
getopts( "dvah:t:u:n:T:", \%opts ) ||
    Usage( "Invalid options" );

my $verbose = $opts{"v"};
my $debug   = $opts{"d"};
$verbose++ if $debug;
my $admutil = $opts{"a"};
my $dohost  = $opts{"h"};
my $time    = $opts{"t"};
my $thost   = $opts{"T"};

$dohost =~ tr/A-Z/a-z/;

$time = "0:01" unless $time;

#
#  Default user
#
my $user = $opts{"u"} || (getpwuid($<))[0];
my $wuser = (getpwuid($<))[0];

#
#  Store information as follows:
#
#  $cron->{user}->{host}->{ cron }->[ min hour day mon weekday args ]
#                       ->{ nightly }->{order}
my $cron = {};
my $cwd = cwd;

#
#  OK, now we are ready!;
#
foreach my $file ( @ARGV ) {
    if ( -d $file ) {
	print "Skipping directory \"$file\"....\n" if $verbose;
	next;
    }

    die "Cannot open/read \"$file\". [$!]\n"
	unless open( FILE, $file );

    #
    #  Convert file relative.
    #
    unless ( $file =~ m:^/: ) {
	$file = "$cwd/$file";
	$file =~ s://:/:g;
	while ( $file =~ s:[^/]+/\.\./:: ) { 1 };
    }
    #
    #  Storage units
    #
    my $tmpgroup;
    my $tmpjob;
    my $tmpuser;

    while(<FILE>) {
	my $command;
	do {
	    next unless s/^#CRON:\s*(\w+)\s*//;
	    $command = $1;
	};
	s/#.*$//;

	# netgroup or host
	    #
	    #  Build the job list
	    #
	if (($command eq 'netgroup') or
	    $command eq 'host') {
	    my ($day, @exclude, $host, $hostexpr, $hour, $ignore, $min, $mon, $weekday, @args);
	    #
	    # The value of $host is the netgroup name, here.
	    #
	    if ($command eq 'netgroup') {
		do {
		    /\(?(([^(].*?)(?=\))|(\@\w+))(.*)/;
		    $hostexpr = $1;
		    ($ignore, $min, $hour, $day, $mon, $weekday, @args ) = split /\s+/, $4;
		    $min =~ s/\)//;



( run in 1.994 second using v1.01-cache-2.11-cpan-ecdf5575e8d )