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

    What should we do about network-effect monopolies?

    Many large companies today are software monopolies that give their product away for free to get monopoly status, then do horrible things. Can we do anything about this?

    via benkuhn.net July 5, 2020

    More on the Deutschlandtakt

    The Deutschlandtakt plans are out now. They cover investment through 2040, but even beforehand, there’s a plan for something like a national integrated timetable by 2030, with trains connecting the major cities every 30 minutes rather than hourly. But the…

    via Pedestrian Observations July 1, 2020

    How do cars fare in crash tests they're not specifically optimized for?

    Any time you have a benchmark that gets taken seriously, some people will start gaming the benchmark. Some famous examples in computing are the CPU benchmark specfp and video game benchmarks. With specfp, Sun managed to increase its score on 179.art (a su…

    via Posts on Dan Luu June 30, 2020

    more     (via openring)


  • Posts
  • RSS
  • ◂◂RSS
  • Contact