LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-19-2009, 09:52 AM   #1
kregec05
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Rep: Reputation: 0
Question Only execute 2nd command on successufl execution of 1st command


Hallo!

I have a script which builds a project and then runs junit tests.
However, if the build fails, the junit tests fail with the same error message.
Therefore the command which runs the junit tests should only be executed if the build was successful.

Do you know a solution to this?
 
Old 08-19-2009, 09:55 AM   #2
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Use &&

Command1 && command2

Command2 will execute only when command1 executes successfully
 
Old 08-19-2009, 10:14 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
PMP's suggestion works if the failed command sets a non-zero exit status (which almost all do). If it doesn't you need to capture the output and parse it for signs of success or failure
Code:
output="$(command 2>&1)"
The parsing is, of course, dependent on the particular command.
 
Old 08-19-2009, 10:29 AM   #4
kregec05
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
works, thank you!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
command execution time minil Programming 10 08-20-2010 04:59 PM
command execution gr8linux Linux - Newbie 14 05-28-2009 02:28 AM
Execute a command , reboot and then execute another command ganeshp@moris.org Linux - Newbie 3 12-03-2008 12:51 AM
remote command execute telnet with 1 command MPowers Linux - Networking 2 06-30-2005 06:31 AM
command execution leonidas Linux - General 1 09-22-2004 12:29 AM


All times are GMT -5. The time now is 10:56 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration