by ayewo · 4y ago · 0 comments
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. 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/
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.
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
}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.
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#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