#!/usr/bin/perl -w use strict; use File::Basename; use Getopt::Long; use Time::HiRes qw ( sleep ); use Pod::Usage; $0 = basename $0; my ($time,$file,$cmd,$verbose,$help,$many_cmds); # read in the command line options GetOptions( 'time=f' => \$time, 'multiple-cmds' => \$many_cmds, 'help' => \$help, 'verbose' => \$verbose ) || pod2usage(2); # print a help message if requested if ( $help ) { pod2usage( -verbose => 2 ); } # exit with a help message if called incorrectly if ( !$ARGV[0] || !$ARGV[1] ) { pod2usage(2); } # correctly split up the files and commands my ( @files,@cmds ); if ( $many_cmds ) { @cmds = split /,/, (pop @ARGV); } else { @cmds = pop( @ARGV ); } @files = @ARGV; # correctly set $time if not set from the command line if ( !$time ) { $time = 0.25 }; $SIG{'INT'} = \&catch_sigint; my %modtime; # keeps track of file modification times for each file foreach my $file (@files) { $modtime{ $file } = (stat($file))[9]; if ( $verbose ) { print "Watching $file, initial mtime is $modtime{$file}\n"; } } if ( $new != $modtime{$file} ) { $modtime{$file} = $new; if ( $verbose ) { print "$file last modified at $modtime{$file}.\n" } ; foreach my $cmd (@cmds) { print "Executing $cmd ... "; system( $cmd ); print "done.\n"; } } } } ############### # Subroutines # ############### sub catch_sigint { print STDERR "\nExiting $0 ...\n"; exit 1; } ##################### # Usage Information # ##################### =head1 NAME helios - automatic file monitoring and command execution =head1 SYNOPSIS helios [options] file1 [file2 ...] command(s) options: --time number_of_seconds --verbose --multiple-cmds --help =head1 OPTIONS =item B<--multiple-cmds> Indicates that a comma-separated list of commands is supplied on the command line. Each command will be executed in succession after a file is modified. =item B<--time> Sets the time (in seconds) between checks of the filename. Defaults to 1 second. Warning: accurate monitoring of time less than a second is not guaranteed, see the Time::HiRes manpage fmodification times, and t +he commands executed. =head1 EXAMPLES # Monitor HelloWorld.java and HellWorld2.java, execute 'javac *.java' # when either of these has changed $ helios HelloWorld.java HelloWorld2.java 'javac *.java' # Monitor myFile.java, execute the commands 'javac *.java' and 'java # myFile' when the file has changed. $ helios --multiple-cmds myFile.java 'javac *.java','java myFile' # Monitor HelloWorld.java every 0.25 seconds, execute 'javac *.java # when the file has changed. $ helios --time 0.25 --verbose HelloWorld.java 'javac *.java' =head1 DESCRIPTION B<helios> will monitor a file for changes and execute a command whenever that file changes. It is named after the Greek god Helios, the god of sun and sight. While multiple files can be separated by spaces, commands should always be grouped into a single Development of B<helios> was inspired by the atchange program, originally by Dr. Tom Schneider: <http://www.lecb.ncifcrf.gov/~toms/atchange.html>. B<helios> has a few advantages over the original atchange program: - Support for monitoring of multiple files - Support for executing multiple commands from the command-line - Support for changing the polling time of files - Better platform independence (less reliance on csh) =head1 AUTHOR Tex Thompson <tex@biosysadmin.com> =head1 LICENSE B<helios> is licensed under the GNU GPL license, available from http://www.gnu.org/. =cut

In reply to helios - updated atchange by biosysadmin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.