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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| -----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----- |
| |||
| -----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----- |
| ||||
| +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 |
| Thread Tools | |
| Display Modes | |
|
|