News for hackers. Stuff that matters.

Ask HN: Reminders for long-running shell jobs?

You start a command in a shell and it takes more than a few minutes to finish, so you go work on something else and come back to it later. Any good advice for sending yourself a notice when it finishes?

In my case these jobs are usually run via SSH, so programs that rely on a GUI aren't useful.

( 15 comments | 16 points | on HN )
Re:Ask HN: Reminders for long-running shell jobs? by jerrylives on Tuesday June 27, 2017 @12:56AM (#14642677)
just add something like `&& echo "Subject: task completed" | sendmail [email protected]`

if you are running it via ssh you can do 'ssh [email protected] bash -s' < local_script.sh` and then do whatever you want to do afterwards

running things locally like make or tests i like to put `&& say done` at the end so i don't lose track of it.

Re:Ask HN: Reminders for long-running shell jobs? by pigpigs on Tuesday June 27, 2017 @07:04AM (#14644185)
I personally curl a slack webhook that sends me a message.

If the task is already running, ctrl + z and run bg. Then i run `wait <pid> && slack 'job done' `

Re:Ask HN: Reminders for long-running shell jobs? by simon_acca on Tuesday June 27, 2017 @08:00AM (#14644533)
I use this little CLI utility that I wrote to send messages on Telegram via a Bot. https://github.com/simonacca/TellTg

All you have to do is `$ my_long_running_job; telltg "Done"` and you get a notification on all your devices. Very handy also for remote jobs.

The best use case so far has been piping the udev log into it when my laptop is locked in a public place and I'm away. I get a notification on my phone when someone open/closes the lid, unplugs the charger, sticks a USB drive in and so on.

Re:Ask HN: Reminders for long-running shell jobs? by pigpigs on Tuesday June 27, 2017 @10:17AM (#14645576)
Cool! May I ask how do you hook it up with opening / closing lid, sticking usb drive etc?
Re:Ask HN: Reminders for long-running shell jobs? by simon_acca on Tuesday June 27, 2017 @05:08PM (#14649463)
I simply do `udevadm monitor | telltg & i3lock`.

It's ugly to look at, but the idea is that you should never receive any logs, if you do, don't look at them but rather get your laptop in sight quickly because something is happening to it (I use it in the public library or such settings).

Re:Ask HN: Reminders for long-running shell jobs? by tedmiston on Tuesday June 27, 2017 @03:12PM (#14648344)
If you happen to be on OS X, you can fire a notification into Notification Center from the terminal.

    osascript -e 'display notification "that thing is done" with title "my awesome title"'
iTerm2 has a similar feature called Triggers [1].

[1]: https://www.iterm2.com/documentation-triggers.html

Re:Ask HN: Reminders for long-running shell jobs? by ezekg on Wednesday June 28, 2017 @03:33PM (#14657476)
If it's important, I've used https://cronitor.io/ in the past to make sure that it finished successfully (single monitor is free).

If it's unimportant, I'd probably just use a Slack webhook like pigpigs mentioned or a growl notification.

Re:Ask HN: Reminders for long-running shell jobs? by richardknop on Tuesday June 27, 2017 @06:15AM (#14643846)
I would probably wrap the shell command in a file and at the end of the file either fire off an email to yourself, or send a text message, or call a notification API - whichever works best for you.
Re:Ask HN: Reminders for long-running shell jobs? by weitzj on Tuesday June 27, 2017 @02:46AM (#14642995)
I put the job in a separate tmux window. When something/a character changes in the window, its color changes and I know I can look what happened.
Re:Ask HN: Reminders for long-running shell jobs? by meta_AU on Tuesday June 27, 2017 @03:53AM (#14643267)
I use zsh, it has a variable called REPORTTIME that will print a report after long running commands. I have a custom report that includes the bell special character.

This way any long running process will bell when it is done and also show the runtime and cpu time of the process.

Re:Ask HN: Reminders for long-running shell jobs? by atsaloli on Tuesday June 27, 2017 @02:01PM (#14647661)
I use "; mail" too but if I forgot and need a notification after I've already launched the job "strace -f -p PID; mail" will email you once the job completes. You have to know the PID of the job.
Re:Ask HN: Reminders for long-running shell jobs? by MichaelBurge on Tuesday June 27, 2017 @08:30AM (#14644756)
Sometimes I add a "; mail" at the end of long-running commands.
Re:Ask HN: Reminders for long-running shell jobs? by ahoka on Wednesday June 28, 2017 @06:32AM (#14653005)
The most unixy way is simply using the terminal 'bell':

sleep 10 ; echo -e \\a

Don't forget to set your terminal to notify you on bell. For example putty can flash the task bar icon.

Re:Ask HN: Reminders for long-running shell jobs? by Davidbrcz on Tuesday June 27, 2017 @02:05AM (#14642885)
Have a look at liquid prompt https://github.com/nojhan/liquidprompt
Re:Ask HN: Reminders for long-running shell jobs? by 12s12m on Tuesday June 27, 2017 @03:27AM (#14643176)
This is an interesting problem :) For my local commands I have a small script called `b` which runs a command and shows a notification when it is done using notify-send.