From: TJ Luoma <tj@luo.ma>
To: Alex Satrapa <grail@goldweb.com.au>
Cc: Zsh-Users List <zsh-users@zsh.org>
Subject: Re: trying to create a "|| failed" function
Date: Thu, 14 Mar 2013 23:19:10 -0400 [thread overview]
Message-ID: <CADjGqHu7f+4-=Tq2w1zd6OB-sA+zK_NE9S5eEn55AfRAwjnoHg@mail.gmail.com> (raw)
In-Reply-To: <C553B1A4-239C-49A9-98FD-1567C3F5936E@goldweb.com.au>
[-- Attachment #1: Type: text/plain, Size: 1140 bytes --]
On Thu, Mar 14, 2013 at 9:55 PM, Alex Satrapa <grail@goldweb.com.au> wrote:
> Or go even further and have "failed" run the command:
>
> notify_if_failed foo with parameters
>
> Then notify_if_filed would contain run $@, evaluate the result and return
> the appropriate exit code, performing any required logging along the way.
>
>
Hrm. I hadn't thought about that.
Here's what I have:
log () {
export LOG="$HOME/Desktop/$NAME.log.txt"
zmodload zsh/datetime
TIME=$(strftime %Y-%m-%d--%H.%M.%S "$EPOCHSECONDS")
OUTPUT=`$@ 2>&1`
EXIT="$?"
if [[ "$EXIT" != "0" ]]
then
# failed
echo "$NAME [$TIME]: $@ failed\nOUTPUT: >$OUTPUT<\nExit: >$EXIT<" | tee -a
"$LOG"
exit $EXIT
fi
}
so now I can run
log foo
and have it logged and exit if it necessary. This seems very useful.
Hrm. Actually, I can add logging of successful commands which have output
as well. Again, very handy.
Anything I can or "should" do differently in the function above? Always
open to ideas, as I usually find that I don't think of the most efficient
way of doing things, I just find something that works (or seems to) and go
with that :-)
Thanks!
TjL
next prev parent reply other threads:[~2013-03-15 3:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-15 1:39 TJ Luoma
2013-03-15 1:55 ` Alex Satrapa
2013-03-15 3:19 ` TJ Luoma [this message]
2013-03-15 5:08 ` Phil Pennock
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADjGqHu7f+4-=Tq2w1zd6OB-sA+zK_NE9S5eEn55AfRAwjnoHg@mail.gmail.com' \
--to=tj@luo.ma \
--cc=grail@goldweb.com.au \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).