While working in my robotics lab, a common situation arises: I want to run a script or train a neural network that may take anywhere from a few minutes to a few hours. I don’t know how long it will take the program to complete, and I don’t want to have to babysit the terminal it’s running in. I’ve found two good ways to alert myself when these scripts complete.

Method 1: System Notification

The program notify-send provides an easy way to alert yourself, by generating system notifications:

echo "hello there"; notify-send "Script complete!

Using a semicolon between the two commands (instead of &&) ensures that the notification will be generated, even if the first command exits early with an error.

Using notify-send works reasonably well and it’s extremely easy (no installation required!). However, it has a few drawbacks:

  • The notification automatically goes away after some time, so you may miss it.
  • It only works when you are actively working on the computer that is running your script. If you are SSH’d into a remote machine or away from the computer, tough luck.

Method 2: IFTTT SMS Message

Sometimes I may even want to go home, grab dinner, or even go to bed if a script is extra long-running. The most convenient way I’ve found to alert myself in these situations is with a text message – I won’t miss it, and it reaches me wherever I am. I’ve set up an automatic texting system using the service IFTTT. Here’s how to set it up:

  • Create an IFTTT account and log in.
  • Go to https://ifttt.com/create to create a new IFTTT applet.
  • For “this”, choose Webhooks and then Receive a web request.
  • Set the Event Name to alert. Finish “this” by pressing the Create trigger button.
You can set the name to anything else, just be sure to update the curl call (see below) to match.
  • Click “that” and choose SMS, then Send me an SMS.
  • Edit the message to include {{Value1}} somewhere in the body. You can get pretty fancy here, but I like to keep it simple.
Here’s the message I like to use.
  • Press the Create action and then Finish buttons to complete your IFTTT applet.

Now your applet is all set up, we just have to trigger it from the command line! I added the following command to my .bashrc file:

alias textme="curl --header \"Content-Type: application/json\" --request POST --data '{\"value1\":\"Script complete\"}' https://maker.ifttt.com/trigger/alert/with/key/<your_key>; echo"

Make sure to replace <your_key> with your own IFTTT key, which you can get by going to this page and clicking the Documentation button near the top of the screen. And of course, you can replace “Script complete” with any other message of your choice.

Finally, to use the textme command we just created, try running this in your terminal:

echo "Hello world"; textme

Using a semicolon between the two commands (instead of &&) ensures that the text message will be sent, even if the first command exits early with an error.

And that’s it! You can send text messages to your phone from the terminal. They may be delayed by a few seconds, but what is a few seconds when your script takes hours?

If you have any other cool ways to alert yourself when terminal commands finish, leave a comment below!

I hope you enjoyed this article. If you’d like to receive emails when I post new content, please sign up for my mailing list below.