From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9679 invoked by alias); 15 Mar 2013 03:19:59 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17702 Received: (qmail 4816 invoked from network); 15 Mar 2013 03:19:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, HTML_MESSAGE,RCVD_IN_DNSWL_LOW,T_DKIM_INVALID autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.210.177 as permitted sender) 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== X-Received: by 10.50.77.230 with SMTP id v6mr298429igw.29.1363317591291; Thu, 14 Mar 2013 20:19:51 -0700 (PDT) MIME-Version: 1.0 Sender: luomat@gmail.com In-Reply-To: References: From: TJ Luoma Date: Thu, 14 Mar 2013 23:19:10 -0400 X-Google-Sender-Auth: FRvgETsgcaw1X7veLgK43Gb0cvA Message-ID: Subject: Re: trying to create a "|| failed" function To: Alex Satrapa Cc: Zsh-Users List Content-Type: multipart/alternative; boundary=e89a8f3ba87fbf12a204d7ee1cc8 --e89a8f3ba87fbf12a204d7ee1cc8 Content-Type: text/plain; charset=UTF-8 On Thu, Mar 14, 2013 at 9:55 PM, Alex Satrapa 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 --e89a8f3ba87fbf12a204d7ee1cc8--