4 ms·
A CLI tool that can be used to observe and act on the return code and/or output of any CLI tool on Linux. It should have a way to notify [1] the user after a lo
by ayewo 4y ago
A CLI tool that can be used to observe and act on the return code and/or output of any CLI tool on Linux. It should have a way to notify [1] the user after a long-running CLI program terminates on Linux.
It would have similar semantics to the time utility. Let's call this tool timed.
For instance, prefixing any task with the time utility e.g. "time dd if=/dev/sda of=/dev/sdb" would output the duration of the underlying task.
Similarly, executing "timed dd if=/dev/sda of=/dev/sdb" would send a notification to the user when the task completes containing the return code and any console output.
1: Paired with something like https://github.com/binwiederhier/ntfy https://github.com/binwiederhier/ntfy. This would allow a user to set up multiple ways to receive the notification, including Telegram/Slack, SMS, push notification, email or simply just turning console outputs into a continuous audio note similar to http://listen.hatnote.com/ http://listen.hatnote.com/
- PhilippGille 4y agoI haven't checked how configurable it is, but on Fedora 35 when you start a long running task in the Gnome terminal and then change the focus to another app, you'll get a system notification when the command in the terminal completes.
- a-dub 4y agoyeah i've considered something like this. "send a screenshot to my phone of the terminal when activity has stopped for at least x minutes." tmux has some facility for this now (although i think there's some weird limitation where it can only be setup for panes and not individual windows), it just needs some scripting to capture the contents of the window and send it off.
- stonewareslord 4y agontfy already supports sending messages after long running commands: ntfy done sleep 10 If you want to also capture output, you can just use a simple bash function: ntfy_done_output() { local TEMP_FILE="$(mktemp)" SUCCESS LOG "${@}" 2>&1 | tee "${TEMP_FILE}" SUCCESS="$((!PIPESTATUS[0]))" LOG="$(curl -fLX POST -T- <"${TEMP_FILE}" some-pastebin.example.com)" if ((SUCCESS)); then ntfy send "Success! Log: ${LOG}" else ntfy send "Failed :(. Log: ${LOG}" fi }
- encoderer 4y agoYou can use Cronitor like this. 1. Create a free monitor and activate an on-complete callback (telegram, slack, or webhook. 2. Install CronitorCli (a single statically linked golang binary) 3. Run any command using Cronitor exec: cronitor exec <monitor key> dd if=/dev/sda of=/dev/sdb Execution history and up to 100MB of output will be logged in Cronitor, including performance metrics, exit codes, etc. You can be alerted on failure, on success, or on start, or any combination of those.
- avg_dev 4y agoI was thinking hard about this and truth is I did write code to do it. From the README.MD in my private repo: > `ec` prints out the elapsed time and exit code of a command after running it. But the thing is, Bash supports this natively, using `$?` and you can even put it in your `$PS1` so you see it for every command, or use a function: https://wiki.archlinux.org/title/Bash/Prompt_customization#Visualizing_exit_codes https://wiki.archlinux.org/title/Bash/Prompt_customization#V... Still, I like my solution. It was fun to write. If you want access to the repo let me have an email address I can write you at, or a GitHub username, and I'll let you have a look. https://i.imgur.com/DUf9gDc.png https://i.imgur.com/DUf9gDc.png