Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

5 Answers 5

up vote 32 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-only-if-success &
command || command-after-only-if-fail &

If the command has already started you may use job control to suspend it, then return it to the foreground with fg chained with your notification:

command
# enter Ctrl-z
fg ; 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" '
    

    You could have it say something to you:

    say "Job finished"
    

    Or you could use Mountain Lion's notification system:

    sudo gem install terminal-notifier # <= only need to do this once
    terminal-notifier -message "Job finished!" -title "Info"
    
  • 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 --passivepopup 'Job finished'
    
share|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
1  
on Mac OS X, you can also use the command-line utility "say". there are also many voices available, check "say -h" ;) –  trinth Oct 10 '12 at 18:28
    
Excellent Answer! –  SunnyShah Oct 30 '12 at 13:04

On unix-like systems you can ring the audible-bell:

echo -e "\a"
share|improve this answer
    
This is really useful in addition to a message notification on mac –  Sirens Apr 1 '13 at 18:49

I have just begun using notifu for desktop notifications from Cygwin. It's a command line notification app for Windows.

Example:

ls -l && /c/notifu-1.6/notifu64 /m "This is a simple Notifu message."
share|improve this answer

I create a simple tool that does exactly this. https://github.com/vikfroberg/brb

Installation

$ npm install -g brb

Instructions

$ sleep 3; brb
share|improve this answer

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.

share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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