Re: Quick Question On Exit Status'
- From: "Zfs.." <cian.scripter@xxxxxxxxx>
- Date: Thu, 22 Jan 2009 02:47:01 -0800 (PST)
On Jan 22, 10:35 am, Janis Papanagnou <janis_papanag...@xxxxxxxxxxx>
wrote:
Zfs.. wrote:
Folks,
Hope someone can clear this up for me.
I have the need to write a script with a function in it called check
()
This function checks for a process and if it exists should return a
code of say 99 back to the main script.
The main script should then test for this status and if it was not
successful should update a config file to reflect that.
As below:
#!/bin/ksh
check ()
{
if ps -ef | grep my_proc
then
echo "Script cannot continue with this proc running"
echo "Exiting"
return 120
else
echo "Proc is not there, proceeding with script"
fi
}
Then test for this condition in main script,
check
if [[ $? != 0 ]]
then
echo "Exited with 99"
exit 99
else
echo "Success"
fi
Trouble is, this seems to always produce a status code of 0 ? Even
doing a truss on it it says it exits with 99 but doing
$? returns 0
Any ideas ?
I guess you are using PD ksh? And running into the function's else
branch, maybe? (Or what version is your ksh?)
Janis
TIA
Excuse my ignorance, I am using Solaris 9 /bin/ksh if thats any use.
I have added a sleep to the function and then trussed the PID. Here is
the output if its of any use.
root@host# ps -ef |grep test
root 7556 3408 0 10:43:15 pts/6 0:00 grep test
root 7549 23269 0 10:43:13 pts/3 0:00 /bin/ksh ./check
root 7552 7549 0 10:43:13 pts/3 0:00 /bin/ksh ./check
root@host# truss -p 7549
waitid(P_ALL, 0, 0xFFBFEB28, WEXITED|WTRAPPED|WSTOPPED|WCONTINUED)
(sleeping...)
waitid(P_ALL, 0, 0xFFBFEB28, WEXITED|WTRAPPED|WSTOPPED|WCONTINUED) = 0
sigaction(SIGCLD, 0xFFBFEAE8, 0xFFBFEB68) = 0
Received signal #18, SIGCLD [caught]
siginfo: SIGCLD CLD_EXITED pid=7552 status=0x0063
setcontext(0xFFBFE7D0)
sigaction(SIGCLD, 0xFFBFEA88, 0xFFBFEB08) = 0
waitid(P_ALL, 0, 0xFFBFEAC8, WEXITED|WTRAPPED|WSTOPPED|WCONTINUED|
WNOHANG) = 0
sysconfig(_CONFIG_CHILD_MAX) = 2000
waitid(P_ALL, 0, 0xFFBFEAC8, WEXITED|WTRAPPED|WSTOPPED|WCONTINUED|
WNOHANG) Err#10 ECHILD
sigaction(SIGCLD, 0xFFBFEA88, 0xFFBFEB08) = 0
close(0) = 0
fcntl(11, F_DUPFD, 0x00000000) = 0
close(11) = 0
fcntl(0, F_SETFD, 0x00000000) = 0
sigaction(SIGCLD, 0xFFBFEAE8, 0xFFBFEB68) = 0
waitid(P_ALL, 0, 0xFFBFEB28, WEXITED|WTRAPPED|WSTOPPED|WCONTINUED|
WNOHANG) Err#10 ECHILD
sigaction(SIGCLD, 0xFFBFEAE8, 0xFFBFEB68) = 0
_exit(0)
Other PID's Truss is
root@extract# truss -p 7552
waitid(P_ALL, 0, 0xFFBFDB10, WEXITED|WTRAPPED|WSTOPPED|WCONTINUED)
(sleeping...)
waitid(P_ALL, 0, 0xFFBFDB10, WEXITED|WTRAPPED|WSTOPPED|WCONTINUED) = 0
sigaction(SIGCLD, 0xFFBFDAD0, 0xFFBFDB50) = 0
pipe() = 3 [4]
fcntl(3, F_DUPFD, 0x0000000A) = 10
close(3) = 0
fcntl(4, F_DUPFD, 0x0000000A) = 11
close(4) = 0
fork() = 7560
close(11) = 0
pipe() = 3 [4]
fcntl(3, F_DUPFD, 0x0000000A) = 11
close(3) = 0
fcntl(4, F_DUPFD, 0x0000000A) = 12
close(4) = 0
fork() = 7561
close(10) = 0
close(12) = 0
fcntl(0, F_DUPFD, 0x0000000A) = 10
fcntl(10, F_GETFD, 0x00000000) = 0
fcntl(10, F_SETFD, 0x00000001) = 0
close(0) = 0
fcntl(11, F_DUPFD, 0x00000000) = 0
close(11) = 0
sigprocmask(SIG_BLOCK, 0x00053840, 0xFFBFD6D8) = 0
stat64("/usr/sbin/egrep", 0xFFBFD640) Err#2 ENOENT
sigprocmask(SIG_SETMASK, 0xFFBFD6D8, 0x00000000) = 0
sigprocmask(SIG_BLOCK, 0x00053840, 0xFFBFD6D8) = 0
stat64("/usr/bin/egrep", 0xFFBFD640) = 0
sigprocmask(SIG_SETMASK, 0xFFBFD6D8, 0x00000000) = 0
write(2, " + e g r e p - v g".., 27) = 27
fork() = 7562
sigaction(SIGCLD, 0xFFBFD640, 0xFFBFD6C0) = 0
waitid(P_ALL, 0, 0xFFBFD680, WEXITED|WTRAPPED|WSTOPPED|WCONTINUED) = 0
waitid(P_ALL, 0, 0xFFBFD680, WEXITED|WTRAPPED|WSTOPPED|WCONTINUED) = 0
waitid(P_ALL, 0, 0xFFBFD680, WEXITED|WTRAPPED|WSTOPPED|WCONTINUED) = 0
sigaction(SIGCLD, 0xFFBFD640, 0xFFBFD6C0) = 0
close(0) = 0
fcntl(10, F_DUPFD, 0x00000000) = 0
close(10) = 0
fcntl(0, F_SETFD, 0x00000000) = 0
sigaction(SIGCLD, 0xFFBFD640, 0xFFBFD6C0) = 0
waitid(P_ALL, 0, 0xFFBFD680, WEXITED|WTRAPPED|WSTOPPED|WCONTINUED|
WNOHANG) Err#10 ECHILD
sigaction(SIGCLD, 0xFFBFD640, 0xFFBFD6C0) = 0
sigprocmask(SIG_BLOCK, 0x00053840, 0xFFBFD678) = 0
stat64("/usr/sbin/echo", 0xFFBFD5E0) Err#2 ENOENT
sigprocmask(SIG_SETMASK, 0xFFBFD678, 0x00000000) = 0
sigprocmask(SIG_BLOCK, 0x00053840, 0xFFBFD678) = 0
stat64("/usr/bin/echo", 0xFFBFD5E0) = 0
sigprocmask(SIG_SETMASK, 0xFFBFD678, 0x00000000) = 0
fcntl(1, F_GETFL, 0x00000000) = 2
write(2, " + e c h o C h e c k".., 63) = 63
write(1, " C h e c k p o i n t c".., 56) = 56
write(2, " + e c h o E x i t i".., 15) = 15
write(1, " E x i t i n g\n", 8) = 8
write(2, " + r e t u r n 1 2 0".., 13) = 13
write(1, " E x i t i n g w i t h".., 16) = 16
_exit(99)
???
.
- Follow-Ups:
- Re: Quick Question On Exit Status'
- From: Janis Papanagnou
- Re: Quick Question On Exit Status'
- References:
- Quick Question On Exit Status'
- From: Zfs..
- Re: Quick Question On Exit Status'
- From: Janis Papanagnou
- Quick Question On Exit Status'
- Prev by Date: Re: Quick Question On Exit Status'
- Next by Date: Re: chown to "root" on a mac for xdebug for netbeans for php ide
- Previous by thread: Re: Quick Question On Exit Status'
- Next by thread: Re: Quick Question On Exit Status'
- Index(es):
Relevant Pages
|