I run long backups and would like a notification when they finish, ideally on my phone. Is email the easiest option, or is there something simpler?
How do you get notified when a long terminal command finishes?
Answers
Try a push notification service such as ntfy or Gotify. You can send a message from a shell command and receive it on your phone. That's a pretty direct fit if you don't want to set up email delivery.
For a backup, make the message distinguish success from failure. In a shell, you can use an if statement around the backup command and send a different notification in each branch.
Reply to this answer
Email is perfectly reasonable if the machine can already send it. Run the backup, then use a mail utility to send a short message. A semicolon between the commands runs the mail command whether the backup succeeds or fails, so capture the exit status if you want to report the result.
On the phone, a mail rule or priority sender setting can make those messages more noticeable. The awkward part is getting outgoing mail configured if it isn't already.
Reply to this answer
For a notification on the same Linux desktop, notify-send is a quick option. You can add it after a command, or wire it into an interactive shell so commands above a time threshold trigger a notification automatically.
The automatic route needs some filtering. Editors, pagers, and other programs you deliberately leave open can otherwise produce a lot of noise.
quietly__in_transit:
That won't reach a phone by itself, but it could be enough when the terminal is on a desktop you're already using.
Reply to this answer
If you already use a messaging app, a bot posting to a private channel is another possibility. It takes more setup than appending a simple notification command, but it gives you a place to collect completion messages from different machines.
Keep an eye on volume, though. A notification for every routine job can become easy to ignore.
Reply to this answer
For the simplest local alert, append a command that prints the terminal bell character. It may make a sound depending on your terminal settings. It won't notify your phone, but it requires very little setup.
Reply to this answer
Add your answer
Answers are reviewed before publication.
__satin_slippers:
Gotify is another option if you prefer it over ntfy. Either way, check how your chosen service handles access before putting sensitive details in messages.