Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: trying to create a "|| failed" function
- X-seq: zsh-users 17702
- From: TJ Luoma <tj@xxxxxx>
- To: Alex Satrapa <grail@xxxxxxxxxxxxxx>
- Subject: Re: trying to create a "|| failed" function
- Date: Thu, 14 Mar 2013 23:19:10 -0400
- Cc: Zsh-Users List <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=lbJ5JPrph0AiQvkMYBUBdH4yYFAWkMu7H/rg9rxJzf4=; b=o3CIG4QFu1G/B37bXxKe1BVQ+Zz4bQgQO/sA4edtHcuLAP8W9XzfNhsVYAETGV07d2 78TRnVidhGUg3L15qqwPKqtfoRXp2C/AuE1mBVMkEm0adqMTBQ9E4qRLE6Yz1bSiiwR6 7L1RrEmtSnUeyV5FchhTMo3b1UNvK0IndGpbUq3ZUicnFkxUBbyYl9FuqukhQ2aoOjXa rcfurMt0ULnCMPX/x40v2KNCNds2gpdwhmvVEb4GIqiQVVqwOpe4SA9E9ei7funyyG7p 27BLOC2hxwoJMHCZCIQVxz7Uo5ZD6bGDK6uWMOH9Xof0TXDU7amQcAIU9XrRxpDUEQmJ 6RQw==
- In-reply-to: <C553B1A4-239C-49A9-98FD-1567C3F5936E@goldweb.com.au>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CADjGqHu2rLLEReGyzBOnVbkvEiz+DCR3fMwjf11ACJGeds1q5A@mail.gmail.com> <C553B1A4-239C-49A9-98FD-1567C3F5936E@goldweb.com.au>
- Sender: luomat@xxxxxxxxx
On Thu, Mar 14, 2013 at 9:55 PM, Alex Satrapa <grail@xxxxxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author