Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

procmail modify subject, procmail alter subject, formail get body of message, www.xxxcon, www xxxcon, board.issociate.de, registrieren fehler dll server 0x8002801c, far2 vs near2 raid10, access abfragen aus linux, "Can't send mail: sendmail process failed with error code 69"

Links

XODOX
Impressum

#1: One last command after "exit 1"?

Posted on 2006-02-15 17:10:10 by alfa_44

Hi,

I have a problem in a script that I can't seem to resolve. I'm writing a
series of install scripts, and among other things, I have a fancy little
function check_status... you've ever seen Gentoo's or Mandrake's boot
scripts, with all those fancy little [ OK ] in green and [ FAIL ] in red?
Well, check_status does exactly that. After each function is (silently)
completed, it checks the exit status and then prints a fancy little [OK] or
[FAIL] on the screen.

Now what happens when I define the exit status? I have a function at the
beginning of the script, going:

if [ $UID -eq 0 ]; then
echo "Don't run this script as root"
exit 1
fi

Q: how can I let check_status happen before it exits? So that it prints a
last [FAILED] on the screen?

Suggestions?

Niki Kovacs

PS: I'm running Slackware Linux 10.2

Report this message

#2: Re: One last command after "exit 1"?

Posted on 2006-02-15 17:19:23 by cfajohnson

On 2006-02-15, Niki Kovacs wrote:
> Hi,
>
> I have a problem in a script that I can't seem to resolve. I'm writing a
> series of install scripts, and among other things, I have a fancy little
> function check_status... you've ever seen Gentoo's or Mandrake's boot
> scripts, with all those fancy little [ OK ] in green and [ FAIL ] in red?
> Well, check_status does exactly that. After each function is (silently)
> completed, it checks the exit status and then prints a fancy little [OK] or
> [FAIL] on the screen.
>
> Now what happens when I define the exit status? I have a function at the
> beginning of the script, going:
>
> if [ $UID -eq 0 ]; then
> echo "Don't run this script as root"
> exit 1
> fi
>
> Q: how can I let check_status happen before it exits? So that it prints a
> last [FAILED] on the screen?
>
> Suggestions?

Have you tried:

trap check_status EXIT

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence

Report this message

#3: Re: One last command after "exit 1"?

Posted on 2006-02-15 17:42:11 by joe

Niki Kovacs <mickey@mouse.com> writes:

> I have a problem in a script that I can't seem to resolve. I'm
> writing a series of install scripts, and among other things, I have
> a fancy little function check_status... you've ever seen Gentoo's or
> Mandrake's boot scripts, with all those fancy little [ OK ] in green
> and [ FAIL ] in red? Well, check_status does exactly that. After
> each function is (silently) completed, it checks the exit status and
> then prints a fancy little [OK] or [FAIL] on the screen.
>
> Now what happens when I define the exit status? I have a function at
> the beginning of the script, going:
>
> if [ $UID -eq 0 ]; then
> echo "Don't run this script as root"
> exit 1
> fi
>
> Q: how can I let check_status happen before it exits? So that it
> prints a last [FAILED] on the screen?

Doesn't look like you have to check when you know what status you're
about to return.

I assume you have a function somewhere that prints the [OK] or [FAIL]
after checking, just call it before calling exit.

Joe
--
Gort, klatu barada nikto

Report this message