1

I'm often issuing commands that take some time. For example downloading something using a console download app. If I want to be noticed when the command has finished, I usually do something like this:

$ <do something>; echo '<do something> has finished' | osd_cat

Then I can switch to another window and do something else meanwhile. When it's done, I'll be noticed.

Now my problem is that I'm lazy. Oh well. I just don't want to type this everytime. So I wonder if there's a daemon that could watch running processes and trigger some actions when the processes finish.

I would like config options so I could have control on:

  1. filtering the processes to be watched (for example, watch processes that run at least for a minute)

  2. customizing the command to perform when a process has finished

1

3 Answers 3

2

You could try using Bash's "wait" command to write a little wrapper script Something like:

#!/bin/bash
command=$*

$command &  
wait
osd_cat "$command has finished"

The wait command causes the script to pause until all child processes have returned an exit code. You could also add a little timeout to make sure that you don't wait too long

0

How about just a simple shell script that does the long command for you. Maybe something like this:

#!/bin/sh
# tellme: run a command and tell me when it's done
if [ $# -gt 0 ]; then
    if $*; then
        echo "'$*' has finished" | osd_cat
    else
        echo "'$*' has finished with errors" | osd_cat
    fi
else
    echo "usage: $0 <command>"
fi

Then, you would just run this command:

tellme <do something>

Granted, it isn't a daemon, so I don't think it will help you for things started in the background (e.g. from cron), but it should do the job for interactive commands.

1
  • It's still more to type than just the command itself. That's why I'm wondering if there's a daemon that would work absolutely transparently.
    – Anonymous
    Jul 23, 2009 at 17:18
0

Maybe it's not a daemon, but it serves the same purpose for me. zsh has scriptable hooks executed right before and right after executing any command. You can make them measure wallclock time and run any action (here: notify-send) if the last executed command was long enough. The following in an excerpt from my ~/.zshrc:

preexec () {
  ZSH_CMD_START_TIME="$(date +%s)"
  ZSH_CMD_NAME="$1"
}
precmd () {
  [[ -n "$ZSH_CMD_NAME" ]] && {
    ZSH_LAST_TIME=$(($(date +%s) - $ZSH_CMD_START_TIME))
    [[ $ZSH_LAST_TIME -gt 60 ]] && [[ -n "$DISPLAY" ]] && { which >/dev/null notify-send } && {
      notify-send --urgency=low --category=zsh --expire-time 1500 "ZSH:" '`'"$ZSH_CMD_NAME"'`'" took $ZSH_LAST_TIME seconds."
    }
    ZSH_CMD_NAME=
  }
}

Not the answer you're looking for? Browse other questions tagged .