Hello all,
The following script (sess.sh) runs fine and gives the correct output on a SunOS 5.9 ( default shell =/bin/ksh) but gives incorrect results on a SunOS 5.7 (default shell= /bin/sh). The script logs on to an oracle database and queries the total no of sessions running in the database and passes that number as the return code to the shell script.
You missed this language: "the low-order eight bits (that is, bits 0377) of status are made available" on the exit system call man page. And sure enough...
$ echo "obase=8;315" | bc
473
$ echo "obase=8;59" | bc
73
$
You're just dropping the high bit from the exit code.
Thanks Perderabo for the quick reply but I have to admit that I could not understand your reply. Could you explain a bit more. What should I do to make the script work.
You should not use exit to return values - what if there are more than 256?
It's sqlplus problem:
#!/bin/sh
sessions = $(
sqlplus -s '/as sysdba' <<EOF
column scnt new_value scount
set head off
set feed off
set pages 0
select count(*) scnt from v\$session;
exit
EOF )
echo "sessions= $sessions"
exit