LinuxQuestions.org
Help answer threads with 0 replies.
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 10-16-2008, 05:16 AM   #1
klss
LQ Newbie
 
Registered: Oct 2008
Distribution: Mint
Posts: 22

Rep: Reputation: 15
scripting: How to check if configure or make fails?


Hi folks.

My first post over here at this place. I am a kind of newbie when it comes to advanced scripting and programming.

I've written a script to install Alsa manually:

http://ubuntuforums.org/showthread.p...18#post5792918


The problem is, if a "./configure" or "make" fails during the process, the whole installation gets corrupted.

Within the script I want to check before running the "make install" for each package, if all of the "./configure" and "make" finished without error.

What would be the best way to do this?

THX for your support.

KLSS
 
Old 10-16-2008, 05:34 AM   #2
rigormortis
LQ Newbie
 
Registered: Oct 2008
Posts: 1

Rep: Reputation: 0
./configure && make && make install
 
Old 10-16-2008, 05:35 AM   #3
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
Do you know about the return code of commands?
It tells you if a command failed or succeeded.
it's called $? from the shell
For instance, let's do a simple command and see the return code:
$ ls
$ echo $?
It will print the return code of ls, which is 0 if succeeded and something else if failed.
you can use this code to take action:
$ ls
$ if [ "$?" -ne 0 ]
> then
> echo "Failed"
> fi

You can also use the || and && operators like this:
$ ls || echo "Failed"
$ make || exit 1
$ make && echo "success"
 
Old 10-16-2008, 07:59 AM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by Agrouf View Post
Do you know about the return code of commands?
It tells you if a command failed or succeeded.
it's called $? from the shell
For instance, let's do a simple command and see the return code:
$ ls
$ echo $?
It will print the return code of ls, which is 0 if succeeded and something else if failed.
you can use this code to take action:
$ ls
$ if [ "$?" -ne 0 ]
> then
> echo "Failed"
> fi

You can also use the || and && operators like this:
$ ls || echo "Failed"
$ make || exit 1
$ make && echo "success"
Yep. It all sums up to return codes.

In a script people usually do something in the lines of this:

Code:
function die() {
  echo "$1"
  exit 1 #error
}

./configure || die "configure failed"
make || die "make failed"
su -c 'make install' || die "su or make install failed"
This can be extended to any imaginable limit. The gentoo ebuilds system uses this intensively.

The most basic version would work the same, just chaining them with &&

Code:
./configure && make && su -c 'make install'
If one fails, the next one will not be run. You could use an additional OR to exit or something

Code:
(./configure && make && su -c 'make install') || echo myerror && exit 1

Last edited by i92guboj; 10-17-2008 at 07:07 AM.
 
Old 10-16-2008, 08:36 AM   #5
klss
LQ Newbie
 
Registered: Oct 2008
Distribution: Mint
Posts: 22

Original Poster
Rep: Reputation: 15
Thx a lot folks.

I'll implement your suggestions.

Just a question:

Would it be possible to put the whole process also in a
"while" loop? while true do? Just an idea.

THX again.

Klss
 
Old 10-16-2008, 09:37 AM   #6
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
indeed, do it like this:
while true
do
echo "I must do something here"
[ $? -eq 0 ] || break
done

this will print 'I must do something here' indefinitely, until it fails, which should never happen anyway but...
I don't get how you want to use it for configure and make and make install...

Last edited by Agrouf; 10-16-2008 at 09:39 AM.
 
Old 10-16-2008, 11:50 AM   #7
klss
LQ Newbie
 
Registered: Oct 2008
Distribution: Mint
Posts: 22

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Agrouf View Post
indeed, do it like this:
while true
do
echo "I must do something here"
[ $? -eq 0 ] || break
done

this will print 'I must do something here' indefinitely, until it fails, which should never happen anyway but...
I don't get how you want to use it for configure and make and make install...
Never mind.

I just introduced above proposals to the Alsa upgrade script. I'll see if the script safely runs for the majority of people.

Thx again.
 
  


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
ardour wont configure: configure: error: C preprocessor "/lib/cpp" fails sanity check disciple061 Linux - Software 4 01-22-2005 01:35 PM
configure /lib/cpp fails sanity check johnlittlepeap Fedora 0 12-07-2004 06:52 AM
configure: error: C++ preprocessor fails sanity check Guitarist88 Linux - Newbie 1 08-13-2004 04:23 AM
ncurses-5.3 configure error - fails sanity check itsjustme Linux From Scratch 3 10-04-2003 06:34 PM
glibc configure: fails sanity check Mr. Eek Linux From Scratch 4 05-19-2003 02:24 AM


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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration