Stories
Slash Boxes
Comments
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

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Monday March 05, 2007
09:21 AM

My new .bash_profile

[ #32576 ]

When I ssh into our development server, I automatically CD into a work directory, do a 'cvs up -d' (-d picks up new directories) and then run all of the tests. However, I almost always ssh into dev twice because one window is for my code and another window is for my tests and I'm tired of hitting <ctrl-c> all the time on the second window. With the help of smylers explaining some odd (to me) bits of bash syntax, I now use something like this:

#!/usr/local/bin/bash

if [ -f ~/.bashrc ]; then source ~/.bashrc; fi

cd /home/cpoe/work/main/
timestamp='.login_time'

if [ -e $timestamp ]; then
    last_time=`cat $timestamp`
else
    last_time=0
fi

curr_time=`date +%s`
let elapsed="$curr_time - $last_time"
if [ $elapsed -gt 600 ]   # five minutes
then
    `perl -e 'print time' > $timestamp`
    /usr/bin/cvs up -d
    /usr/local/bin/runtests -lr
fi

With that, if I've ssh'd into the dev server and run the tests within the last five minutes, the next ssh will not do the cvs up or run the tests. It could probably be cleaned up more since I'm not much of a bash programmer, but it's pretty handy.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
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:

    #!/usr/local/bin/bash

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

    timest

    • 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.

        #!/usr/local/bin/bash

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

        timestamp=.login_time

        cd /home/cpoe/work/main/

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

        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 considerat