#!/usr/local/bin/perl # Poor man's "at": execute script or command at a time increment from now # Usage: # at [-c] [ -s sec | -m min | -h hours ] scriptname # -c means script is given on command line (use \>, etc to protect) # (or enclose all in " " ) # (or enclose each in " ") $time = 5; # default wait time $helpline="14"; if ( $ARGV[0] =~ /-he/ ) { system("head -$helpline $0"); exit 0; } chop($name = `basename $0`); if ( $ARGV[0] ne '-c' ) { # Script is file if ( $ARGV[0] !~ /^-(s|m|h)/ ) { $script = $ARGV[0]; } else { $script = $ARGV[2]; } if ( ! -f $script ) { print STDOUT "Script $script does not exist"; exit 1; } } else { # Script is rest of command line shift; if ( $ARGV[0] !~ /^-(s|m|h)/ ) { $script = join(' ',@ARGV[0 .. $#ARGV]); } else { $script = join(' ',@ARGV[2 .. $#ARGV]); } print "$name: script is: $script\n"; } if ( $ARGV[0] eq '-s' ) { $time = $ARGV[1]; } elsif ( $ARGV[0] eq '-m' ) { $time = $ARGV[1]*60; } elsif ( $ARGV[0] eq '-h' ) { $time = $ARGV[1]*3600; } if ( $time < 0 ) { $time = 10; } # just in case if ( $pid = fork ) { # fork child to sleep then run exit 0; } elsif ( defined $pid ) { sleep $time; eval system "$script"; exit 0; }