Script that works on one server does not work on another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script that works on one server does not work on another
# 1  
Old 05-08-2008
Script that works on one server does not work on another

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.


sess_warning.sh
----------------
#!/bin/sh
sqlplus -s '/as sysdba' <<EOF
column scnt new_value scount
select count(*) scnt from v\$session;
exit scount
EOF
echo "sessions= $?"
exit

OS= SunOS 5.9, default shell =/bin/ksh ( gives correct result)
----------------------------------------------------------

scott@westpark> ./sess.sh 2>sess_err.log

SCNT
----------
94

sessions= 94



OS= SunOS 5.7, default shell =/bin/sh ( gives incorrect result)
----------------------------------------------------------

$ ./sess.sh 2> sess_err.log

SCNT
----------
315

sessions= 59

Am I missing something here?

Thanks
# 2  
Old 05-08-2008
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...
Code:
$ echo "obase=8;315"  | bc
473
$ echo "obase=8;59"  | bc
73
$

You're just dropping the high bit from the exit code.
# 3  
Old 05-08-2008
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.

Thanks.
# 4  
Old 05-08-2008
The exit code is only an 8-bit number. 315 is too big a number to fit into 8 bits.

Try this instead:

Code:
#!/bin/sh
echo sessions=`sqlplus -s '/as sysdba' <<EOF
column scnt new_value scount
select count(*) scnt from v\$session;
exit scount
EOF
`
exit

# 5  
Old 05-08-2008
Thanks. I'll give it a try..
# 6  
Old 05-09-2008
You should not use exit to return values - what if there are more than 256?
It's sqlplus problem:
Code:
#!/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

# 7  
Old 05-11-2008
Thanks Jim, that's where I was heading but my post was rubbish in retrospect!! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

"Mv" command does not work in loop, but works manually

Hi there, this may be a beginner's error, but I've been unable to find a solution on my own and by googling, and now I am really stuck on it. I am simply trying to move directories called for example CAT_Run01.ica to a directory with the corresponding number, Run01, in the same directory. For... (2 Replies)
Discussion started by: andrevol
2 Replies

2. UNIX for Beginners Questions & Answers

Expect scripting issue, works interactively when doing commands in cli, does not work in script

Hi; problem may be obvious, simple but I have to say it is somehow not easy to locate the issue. I am doing some word extracting from multiline text. Interacting in CLI seems to work without issues. First step is to add multiline text to a variable. expect1.1> expect1.1> set... (2 Replies)
Discussion started by: aldowski
2 Replies

3. AIX

PING to AIX works but TELNET FTP SSH doesn't work

root@PRD /> rsh DR KFAFH_DR: protocol failure due to unexpected closure from server end root@PRD /> telnet DR Trying... Connected to DR. Escape character is '^]'. Connection closed. root@PRD /> ftp DR Connected to KFAFH_DR. 421 Service not available, remote server has closed connection... (2 Replies)
Discussion started by: filosophizer
2 Replies

4. Shell Programming and Scripting

Rsync in bash script doesn't work even after placing pub key in target server

Hello Friends, My bash script is like this #!/bin/bash # request Bourne shell as shell for job #$ -S /bin/bash # assume current working directory as paths #$ -cwd #$ -N rsync-copy # # print date and time date rsync -rltD --progress "ssh -i /home/myname/.ssh/id_rsa"... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

5. Solaris

Drop_caches doesn't work on Solaris but works on RHEL6

Hello Experts, I am performing performance tests on a few mysql select queries. I use the following command to clear the memory disk caches. sync && echo 3 | sudo tee /proc/sys/vm/drop_caches I however see that the above command works on RHEL6 but doesn't work on Solaris 10. I asked... (4 Replies)
Discussion started by: Anirudh Kumar
4 Replies

6. UNIX for Dummies Questions & Answers

C-program works fine interactively, but not on the SGE server

Greetings, I have a C-program that is made to implement a hidden Markov model on an input file. The program is very memory intensive. I've installed it on my local server where I have an account and it compiles fine. The way they have the server set up is that you can either work... (1 Reply)
Discussion started by: Twinklefingers
1 Replies

7. Shell Programming and Scripting

sed command works on Fedora/Ubuntu, but doesn't work in Mac

Hi, I have a question. I define a function using sed command: replace() { searchterm=$1 replaceterm=$2 sed -e "s/$searchterm/$replaceterm/ig" $3 > $WORK'tempfile.tmp' mv $WORK'tempfile.tmp' $3 } Then I call replace 'test = 0' 'test = 1' $myfile This code... (1 Reply)
Discussion started by: Dark2Bright
1 Replies

8. Shell Programming and Scripting

sed command works on Fedora/Ubuntu, but doesn't work in Mac

Hi, I have a question. I define a function using sed command: replace() { searchterm=$1 replaceterm=$2 sed -e "s/$searchterm/$replaceterm/ig" $3 > $WORK'tempfile.tmp' mv $WORK'tempfile.tmp' $3 } Then I call replace 'test = 0' 'test = 1' $myfileThis code works well in... (1 Reply)
Discussion started by: Dark2Bright
1 Replies

9. Shell Programming and Scripting

sed works on Linux and Unix does not work

Hi, I use this command in Linux but if I run the same command does not work in freebsd. Follow the below command: Linux works: sed -e '1731a\' -e '####' squid.conf > squid2.conf ; sed -e '1731a\' -e 'acl TESTE_ip src 192.168.1.1/255.255.255.255' squid2.conf > squid.conf ; sed -e... (7 Replies)
Discussion started by: andreirp
7 Replies

10. UNIX for Dummies Questions & Answers

Remote Unix printing to my WinXP works with no router. How can I make it work through my router?

I set up remote printing on a clients Unix server to my Windows XP USB printer. My USB printer is connected directly to my PC (no print server and no network input on printer). With my Win XP PC connected to my cable modem (without the router), i can do lp -dhp842c /etc/hosts and it prints. I... (7 Replies)
Discussion started by: jmhohne
7 Replies
Login or Register to Ask a Question