Live data from Hacker News

Show HN: Alert yourself after a long-running task in terminal

gist.github.com

21–30 of 51 posts

Re: Show HN: Alert yourself after a long-running task in terminal

#21
Here is it for fish, using the postexec event handler:

    function postexec_notify --arg cmd --on-event fish_postexec
      set -l s $pipestatus
      if test "$CMD_DURATION" -ge 25000 && ! string match -rq '(^man|\s--help)(\s|$)' $cmd
        if string match "$status" -qv 0 $s
          terminal-notifier -title $cmd -message 'Exited with '(string join '|' $s)' after '(math $CMD_DURATION / 1000)s
        else
          terminal-notifier -title $cmd -message 'Finished in '(math $CMD_DURATION / 1000)s
        end
      end
    end
As a bonus, this includes the command line in the notification.

I found that this can be somewhat annoying when reading man pages or interactive content though. To remedy this, I tried detecting whether the terminal is focused at the time of command completion, but it doesn't seem possible to get the terminal's pid from fish. The pid of the topmost application can be retrieved with:

    osascript -e 'tell application "System Events" to return unix id of (first process whose its frontmost is true)'

Re: Show HN: Alert yourself after a long-running task in terminal

#23
Personally I have a flask app deployed on heroku that posts a message to a Discord webhook just by visiting an url. So in my case when I use ssh to run long tasks I have at the end "curl https:// .herokuapp.com/?Finished" and as soon as that commands is executed I receive a message either at my phone or computer (through a channel in a personal discord server).

Probably is a bit of a 'hacky' way, and using different proprietary services (heroku and discord) but it works, does it fine, and it's free! (And it was also funny and quick to develop by myself).

The source code is on Github too! https://github.com/TrianguloY/ping

Re: Show HN: Alert yourself after a long-running task in terminal

#24

Personally I have a flask app deployed on heroku that posts a message to a Discord webhook just by visiting an url. So in my case when I use ssh to run long tasks I have at the end "curl https:// .herokuapp.com/?Finished" and as soon as that commands is executed I receive a message either at my phone or computer (through a channel in a personal discord server). Probably is a bit of a 'hacky' way, and using different…

This is a cool idea, I've always wanted to expand this kind of thing to other similar usecases like getting notified after long CI jobs.

I think the repo is private though.

Re: Show HN: Alert yourself after a long-running task in terminal

#25

Personally I have a flask app deployed on heroku that posts a message to a Discord webhook just by visiting an url. So in my case when I use ssh to run long tasks I have at the end "curl https:// .herokuapp.com/?Finished" and as soon as that commands is executed I receive a message either at my phone or computer (through a channel in a personal discord server). Probably is a bit of a 'hacky' way, and using different…

This is a cool idea, I've always wanted to expand this kind of thing to other similar usecases like getting notified after long CI jobs. I think the repo is private though.

Ouch, thanks for noticing, should be public now.

I also made a similar service in the past for Heroku webhooks, to be notified with heroku apps status. Github already have one built-in. https://github.com/TrianguloY/webhook-discord

Webhooks are a really interesting feature!

Re: Show HN: Alert yourself after a long-running task in terminal

#26
Reminds me of my homegrown version of a notifier. Essentially we had a lot of long running tasks that would emit logs. My terminal notifier:

1. Scanned for patterns in these logs periodically.

2. Send out a mail to my Gmail account with specific subjects.

3. I had set up IFTTT[1] on my mobile (android) to scan my inbox and look for certain subject lines^, and trigger playing music.

Worked like a charm for the ~6 months I was on the project.

^ Maybe bodies too, can't remember now, this was in 2015-2016.

[1] https://ifttt.com/

EDIT: I should also note this workflow encouraged quite a bit of fun social interaction. My team knew of this setup, and when my phone would randomly play music, everyone would break into laughter as I hurried back to my desk to troubleshoot!

Re: Show HN: Alert yourself after a long-running task in terminal

#28
Some time ago I also played around with notifications when a long running task occasionally stopped for user input (like apt-get). I had some LD_PRELOAD hack that worked ok, hooking into read calls. I probably lost it, it would be nice to rediscover it again.
Post reply on HN