The place I work has commands that take a long time to execute.

Is there a command/utility that I can use to notify me when the command execution is over? It could be a popup window or maybe a little sound.

link|improve this question

feedback

2 Answers

up vote 1 down vote accepted

Generally, if you know this before running the command, you can just start it with:

command; command-after &

This will execute the command-after after the previous command has exited (regardless of its exit code). The & will start it in background.

If you care about a successful or failure exit, respectively use:

command && command-after &
command || command-after &

Now … what you want to do after this depends on your environment.

  • On any system, you can "ring" the terminal bell. Depends on your exact system what really works (BSD vs. GNU Linux, etc.), but tput bel should do. I couldn't reliably test it right now, though. Search for "ring bell" to find out more.

  • On Mac OS X, you could use AppleScript to pop up a Finder dialog:

    osascript -e 'tell Application "Finder" to display dialog "Job finished" '
    
  • In GNOME, zenity can show a GTK dialog box, called from the command line. See also this Stack Overflow question: showing a message box from a bash script in linux. It can be installed through your favorite package manager.

  • Some distributions might have xmessage. Specifically for GTK environments, there is gxmessage.

  • Ubuntu has a notification system that you can trigger with notify-send.

    notify-send "Job finished!"
    
  • KDE uses kdialog, for example:

    kdialog --title "Job finished!"
    
link|improve this answer
Awesome! Thank you! – Utkarsh Sinha Oct 11 '11 at 20:50
Let me know what command you used! I added some other options as well. – slhck Oct 11 '11 at 20:54
I'm fiddling around with notify-send and xmessage. Both of them seem to be interesting! Here's the next thing I'm looking for - superuser.com/questions/345463/… – Utkarsh Sinha Oct 11 '11 at 21:04
feedback

If you use csh or tcsh as your interactive shell, you can use the notify command:

% long-running-command &
[1] 14431
% notify %1
% 
(later, when the command finishes)
[1]    Done                          long-running-command

You can achieve a similar effect in bash with set -b or set -o notify.

This probably doesn't meet your requirements, since all it does is print a message; I dont' think it can be configured to pop up a window or ring the bell.

link|improve this answer
I'm trying to avoid looking at the shell to find out if a job finished. Thanks, though! – Utkarsh Sinha Oct 11 '11 at 22:20
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.