Networking Forums

Networking Forums > Computer Networking > Linux Networking > cmd1 | gzip -f ... && cmd2 : Command concatenation with condition: Execute cmd2 only if cmd1 (or gzip) fails/succeeds?

Reply
Thread Tools Display Modes

cmd1 | gzip -f ... && cmd2 : Command concatenation with condition: Execute cmd2 only if cmd1 (or gzip) fails/succeeds?

 
 
Matthew Lincoln
Guest
Posts: n/a

 
      06-17-2008, 06:16 AM
I am not sure about on how to specify that a second command should only be execute in case
that the first command fails/succeeds.

When I enter:

cmd1 | gzip -f ... && cmd2

Is then cmd2 executed only if cmd1 is finished successfully or if gzip is finished successfully?

Is the command concatenation "&&" correct at all?

What if I want cmd2 only to execute if both (cmd1 and gzip) end successfully?

What about the other way: cmd2 should only be executed if

a) cmd1 failed

b) cmd1 or gzip failed?

Matthew
 
Reply With Quote
 
 
 
 
Bill Marcum
Guest
Posts: n/a

 
      06-17-2008, 07:18 AM
On 2008-06-17, Matthew Lincoln <(E-Mail Removed)> wrote:
>
>
> I am not sure about on how to specify that a second command should
> only be execute in case that the first command fails/succeeds.
>
> When I enter:
>
> cmd1 | gzip -f ... && cmd2
>
> Is then cmd2 executed only if cmd1 is finished successfully or if gzip
> is finished successfully?
>
> Is the command concatenation "&&" correct at all?
>
> What if I want cmd2 only to execute if both (cmd1 and gzip) end
> successfully?
>
> What about the other way: cmd2 should only be executed if
>
> a) cmd1 failed
>
> b) cmd1 or gzip failed?
>
> Matthew


Use bash and test the PIPESTATUS array.

 
Reply With Quote
 
david
Guest
Posts: n/a

 
      06-17-2008, 09:42 AM
On Tue, 17 Jun 2008 06:16:24 +0000, Matthew Lincoln rearranged some
electrons to say:

> I am not sure about on how to specify that a second command should only
> be execute in case that the first command fails/succeeds.
>
> When I enter:
>
> cmd1 | gzip -f ... && cmd2
>
> Is then cmd2 executed only if cmd1 is finished successfully or if gzip
> is finished successfully?
>
> Is the command concatenation "&&" correct at all?
>
> What if I want cmd2 only to execute if both (cmd1 and gzip) end
> successfully?
>
> What about the other way: cmd2 should only be executed if
>
> a) cmd1 failed
>
> b) cmd1 or gzip failed?
>
> Matthew


Didn't you read the responses the first time you posted this question 3
days ago?

Seems like you would be better off writing a small script to do what you
want.

man bash

 
Reply With Quote
 
Tristan Miller
Guest
Posts: n/a

 
      06-17-2008, 04:31 PM
Greetings.

In article <485756b8$0$6616$(E-Mail Removed)>, Matthew
Lincoln wrote:
> I am not sure about on how to specify that a second command should only
> be execute in case that the first command fails/succeeds.
>
> When I enter:
>
> cmd1 | gzip -f ... && cmd2
>
> Is then cmd2 executed only if cmd1 is finished successfully or if gzip is
> finished successfully?
>
> Is the command concatenation "&&" correct at all?
>
> What if I want cmd2 only to execute if both (cmd1 and gzip) end
> successfully?
>
> What about the other way: cmd2 should only be executed if
>
> a) cmd1 failed
>
> b) cmd1 or gzip failed?


This is pretty trivial to test empirically on your own:

$ true | false && echo foo
$ false | true && echo foo
foo
$ true | true && echo foo
foo
$ false | false && echo foo
$

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
 
Reply With Quote
 
Guillaume Dargaud
Guest
Posts: n/a

 
      06-18-2008, 12:58 PM
Or test the value of $?
--
Guillaume Dargaud
http://www.gdargaud.net/


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why it takes a long time to connect(TCP) in this condition ? joseluismarchetti@yahoo.com.br Linux Networking 4 03-12-2009 02:30 PM
Execute second command only if first fails/succeeds? Matthew Lincoln Linux Networking 3 06-30-2008 01:10 AM
Nslookup succeeds, but ping fails to resolve hostname Curt McNamee Windows Networking 1 11-07-2006 03:04 PM
Affordable Notebook Pc's! Excellent Working Condition ***With Warranty*** kuteatl21boi@gmail.com Broadband 0 04-03-2006 04:11 PM
Netdom verify fails in one direction, but succeeds in the other pehi Windows Networking 0 05-21-2005 07:21 AM



1 2 3 4 5 6 7 8 9 10 11