4

I am running a long process on a remote shell. I would like to trigger a notification when the process is complete. This answer does not suffice, because the long command is on a remote server, so it cannot call terminal-notifier.

I can get close to my desired outcome by using an iTerm2 trigger. For example if I run the following on the remote server and set up an iTerm2 trigger for __FINISHED__:

./long_process && echo "\__FINISHED__"

This has the undesirable feature that every time I scroll back to this command in my editor or my code (I'm running code in an emacs shell), the notification triggers.

One solution might be some kind of text notification that iTerm2 will recognize, but that will not appear in an emacs scrollback buffer.

pnj
  • 157

3 Answers3

8

You can echo a bell - \a in the remote terminal: ./long_process ; echo -e '\a'

Some terminal emulators will play some sort of sound and might show a notifications. iTerm2, in particular, will show a notification and play a sound, if process' tab is not focused.

Also, notice that I used ; to separate commands. This way you will be notify even when command returns non-zero status while && will only run if command succeeds.

KarolisL
  • 181
  • 1
  • 2
8

You have not specified what kind of notification you want nor what OS the remote server is running so I am going to have to make some assumptions here. I will assume you don't really care what type of notification it is as long as you are notified and that the remote server is running some flavor of *nix.

  1. Send yourself an email. If sendmail is configured on the server, you could do

    ./long_process && echo "Job done" | sendmail pnj@yourdomain.com
    
  2. ssh back to your local machine (assuming this is possible) and make it talk to you. See here for more cool ways of making OSX beep at you.

    ./long_process && ssh you@local.ip say "Yo! All done"
    

    or

    ./long_process && ssh you@local.ip terminal-notifier -message "Job finished!" -title "Info"
    

    If you are connecting from a dynamic IP and you have configured your router so that you can ssh to that dynamic IP, you can do this (assuming you are only currently connected from your remote machine):

    ip=$(who | grep $USER | perl -lne 's/\\((.+?)\\)\s*$//; print "$1"' | tail -n 1) &&
     ./long_process && ssh you@$ip terminal-notifier -message "Job finished!" -title "Info"
    

    You can set up password-less ssh in the normal way. It should not be affected by the dynamic IP. Once you have done so, the code above will work.

  3. Use pushover and send a notification to your Android or iOS device (if you have one)

    ./long_process && pushover.pl "All done"
    
terdon
  • 54,564
1

There's a really easy way to cause iTerm2 to bounce in the dock until you switch over to it. It's great. To use it, you just need to use iTerm2 and be able to install software on the host you're ssh'd into. Here's how you do it,

  1. SSH into the host.
  2. Install Shell Integration for iTerm2. On the Mac version of iTerm2 you do this by selecting iTerm2->Install Shell Integration. More info about how to install here if you need it.
  3. Execute your command
./long_process && it2attention start
  1. You can also try
./long_process && it2attention fireworks
Max
  • 144