How do you get phone notifications when long-running commands finish?

0
0
Asked By MellowPine42 On

I regularly run large backups and other commands that can take a long time. I'd like a way to know when one finishes, preferably through a notification on my phone, although desktop alerts, sound, or email would also work. What notification methods or shell setups have you found practical without being too complicated?

5 Answers

Answered By CopperLark7 On

For phone notifications, ntfy and Gotify are both popular options. You can send a message with a simple HTTP request from a shell script. Gotify is especially nice if you want to host it yourself on a home server, VM, container, or LAN, while ntfy is quick to get started with. Telegram bots, Pushover, and similar push services are other straightforward choices.

BrightKite19 -

I’ve had good results with Gotify too. The Android app and curl-based API make it easy to trigger from backup scripts.

Answered By CloudJuniper5 On

For a one-off command, chaining a sound or another local action is often enough: `long_backup && play success.wav || play failure.wav`. You can substitute any command that makes sense, such as a desktop popup, a script that calls a push service, or a request to a device on your network. The main thing is to handle success and failure separately so you don’t mistake a failed backup for a completed one.

Answered By RiverMoss8 On

Email is still one of the simplest and most reliable approaches, especially for servers. You can pipe command output into mail and receive the result on your phone, where you can mark messages from yourself as high priority. It also leaves an archive of what happened, which can be useful for backups and other maintenance jobs.

Answered By QuietOrbit31 On

For local desktop alerts, use notify-send from libnotify. You can add it after a command, for example: `long_backup && notify-send 'Backup finished' || notify-send 'Backup failed'`. If you want this to happen automatically, a shell hook can measure how long interactive commands take and notify you only when they exceed a threshold. It’s also possible to suppress notifications when the terminal window still has focus.

SilverNook6 -

A short delay combined with checking whether the terminal has focus helps avoid notifications for commands that intentionally open another GUI window.

Answered By AmberVale24 On

If the job is running in the background, use the shell’s `wait` builtin rather than polling the process manually: `long_backup & pid=$!; wait "$pid" && notify-send 'Backup complete' || notify-send 'Backup failed'`. For an already-running process, a small loop that checks its PID can work, followed by an alert when it exits.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.