Unix Technical Forum

Slightly OT: one last command AFTER exit 1?

This is a discussion on Slightly OT: one last command AFTER exit 1? within the Slackware Linux Support forums, part of the Unix Operating Systems category; --> Hi, I have a problem in a script that I can't seem to resolve. I'm writing a series of ...


Go Back   Unix Technical Forum > Unix Operating Systems > Slackware Linux Support

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-20-2008, 02:37 PM
Niki Kovacs
 
Posts: n/a
Default Slightly OT: one last command AFTER exit 1?

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-20-2008, 02:37 PM
Blumf
 
Posts: n/a
Default Re: Slightly OT: one last command AFTER exit 1?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Niki Kovacs wrote:
> Q: how can I let check_status happen *before* it exits? So that it prints a
> last [FAILED] on the screen?
>
> Suggestions?


Not sure if it's possible (not really a bash-head), but can you
(re)define 'exit' to be a bash function that does the check_status stuff
and exit normally. Have that specialised 'exit' set at the start of the
relevant scripts.

Blumf


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFD809sMid3IcxolsoRAgZnAJsGIkx+tXLCx9fQmdnSID AR5TkOzQCeL4T9
GcV7q6gs52KxshpJr4aec98=
=5fDC
-----END PGP SIGNATURE-----
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-20-2008, 02:37 PM
+Alan Hicks+
 
Posts: n/a
Default Re: Slightly OT: one last command AFTER exit 1?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In alt.os.linux.slackware, Niki Kovacs dared to utter,
> 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?


Well, you can always run check_status after your rc script.

/etc/rc.d/rc.something
check_status

Perhaps a better solution would be to have check_status do the actual
exiting.

WARNING: Untested junk code follows

check_status() {

if [ $1 = "0" || $1 = "" || $? = 0 ]; then
echo "OK"
else
echo "FAILED"
exit
fi

}

So in the above startup script, you could replace "exit" with
"check_status" and have the effect you want.

- --
It is better to hear the rebuke of the wise,
Than for a man to hear the song of fools.
Ecclesiastes 7:5
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQFD82Ppz8zcalmVmBkRAk/JAKDJ/0V5Jh5cNggd4S7oEQy/B9O3UgCgk4uG
pmLtGczJi6L/Z9sfF2HUWk8=
=WHnK
-----END PGP SIGNATURE-----
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-20-2008, 02:37 PM
Niki Kovacs
 
Posts: n/a
Default Re: Slightly OT: one last command AFTER exit 1?

+Alan Hicks+ wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>


>
> So in the above startup script, you could replace "exit" with
> "check_status" and have the effect you want.


OK thanks very much!

Niki Kovacs



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:04 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com