• Posts
  • RSS
  • ◂◂RSS
  • Contact

  • Run When Done

    May 20th, 2014
    tech  [html]
    If you want to run a command when another finishes, the shell can do that for you:
        $ long_running_process.sh && echo "runs on success"
        $ long_running_process.sh || echo "runs on failure"
        $ long_running_process.sh ;  echo "runs either way"
    
    One common thing to do this with is email, so you get a notification:
        $ long_running_process.sh ; echo done | mail -s done jeff@jefftk.com
    
    (This does require your server to be set up for sending mail in a way that won't get rejected, which is actually kind of tricky.)

    For years, though, I've gotten annoyed at myself when after a process has been running for a while I wish I had set something else to run after it. Should I kill the process and start it over with && something_else.sh, or should I let it finish and then run something_else.sh on my own?

    It turns out you don't have to choose! Shell job control can do this for you. Just background the first command, and then when you foreground it add the next command:

        $ sleep 10
        ^Z
        [1]+  Stopped                 sleep 10
        $ fg ; echo "finished, exit status is $?"
        sleep 10
    (a few seconds of waiting)
        finished, exit status is 0
    
    You can see fg substitutes for the original command, running as long as it would, and passing along the exit status so && and || still work.

    Comment via: google plus, facebook

    Recent posts on blogs I like:

    Who Should Bear the Risk in Infrastructure Projects?

    The answer to the question is the public sector, always. It’s okay to have private-sector involvement in construction, but the risk must be borne by the public sector, or else the private sector will just want more money to compensate for the extra risk. …

    via Pedestrian Observations November 30, 2020

    Fireside Friday, November 27, 2020

    Hey folks! Fireside this week. A bit of a change-up in terms of the coming attractions. I had planned to start “Textiles, How Did They Make It?” next, but I want to do a bit more reading on some of the initial stages of textile production (that is, the pr…

    via A Collection of Unmitigated Pedantry November 27, 2020

    Thoughts you mightn't have thunk about remote meetings

    Welcome to this week's edition of "building a startup in 2020," in which all your meetings are suddenly remote, and you probably weren't prepared for it. I know I wasn't. We started a "fully remote" company back in 2019, but …

    via apenwarr November 23, 2020

    more     (via openring)


  • Posts
  • RSS
  • ◂◂RSS
  • Contact