Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Unlike sh, bash has arithmetic evaluation that would make your script much simpler. I also wouldn’t check for the dotfile’s existence, just read it with error messages suppressed. It’s also bizarre that you’re using date +%s to get the timestamp in one place and perl -e 'print time' in another – and the backticks around that second place are even more so. All in all here’s how I’d write that:


    [ -r ~/.bashrc ] && source ~/.bashrc


    • By the way, I did implement many of your suggestions, thank you. However, I deliberately didn't want to go with the 'don't run tests if there are no updates to CVS'. There are plenty of other ways -- admittedly less common -- that tests can fail even without CVS updates. When those failures occur, I'd like to catch them!

      • Ah. Btw, a much more direct way to do this just occured to me: use the file’s mtime.


        [ -r ~/.bashrc ] && source ~/.bashrc


        cd /home/cpoe/work/main/

        if [[ `find "$timestamp" -mmin +5 -print` ]] ; then
            touch "$timestamp"
            /usr/bin/cvs up -d
            /usr/local/bin/runtests -lr

        The idiomatic bit here is using find to check the file’s age. The -mmin +5 predicate means “if the mtime of the file under consideration is equal to or greater than 5 minutes.” Since file is given only a single filename to check, its output will be empty if that one file was last touched less than 5 minutes ago. The condition is then false, so nothing happens.