1833875 Members
3102 Online
110063 Solutions
New Discussion

bash script problem

 
Marcin Gonet_1
Advisor

bash script problem

Hi,

I've got a problem with a script:

#!/usr/bin/sh
cat << EOF | /usr/bin/su - oracle
DATABASE1
/opt/omni/lbin/open_database
EOF

I get:
-bash: line 1: DATABASE1: command not found
/opt/omni/lbin/open_database: line 1: svrmgrl: command not found

Oracle's shell is bash. On another server, where oracle's shell is tcsh, the same script works just fine.

What is the reason? Any ideas?
Marcin
6 REPLIES 6
Karthik S S
Honored Contributor

Re: bash script problem

Sounds like a profile /PATH problem to me. Try with absolute paths.

-Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
Mark Grant
Honored Contributor

Re: bash script problem

bash runs piplines like this in a sub-shell and any unexported variables are not available. This would be my guess as to what is happening. Export any variables your "open_database" command needs including PATH.

Also though, it looks to me like you are doing, in effect, su - oracle DATABASE1". If there is no command called DATABASE1 then I would expect to tget the error you are. What and where is DATABASE1. Having said this, I still think, if it works in another shell that the "bash" behaviour I mention above is still the most likely culprit.
Never preceed any demonstration with anything more predictive than "watch this"
Marcin Gonet_1
Advisor

Re: bash script problem

It is not a problem of paths or variables.

When I login as oracle I have to choose database name, which is in this case "DATABASE1". I don't know why bash behaves differently than tcsh. When I changed oracle's shell to tcsh it works OK.
Mark Grant
Honored Contributor

Re: bash script problem

Then it appears to me we have found another "bash" oddity.

I have tested this myself now and get the same result as you and it looks to be in a "read" in the .profile.

One way around this would be to change the .profile so that it only asked for which database if $DATABASE is not already defined. Then change your script to something like

/usr/bin/su - oracle -c 'DATABASE=DATABASE1 /opt/omni/lbin/open_database'

Though you might need to do "export DATABASE=DATABASE1" these days.
Never preceed any demonstration with anything more predictive than "watch this"
Mark Grant
Honored Contributor

Re: bash script problem

Just thought of another advantage of the above approach.

If you do it like that in the .profile then users can do this at the login prompt

login: user1 DATABASE=DATABASE6
Password:

This will set the variable when they log in. This feture of log in is often forgotten but is oh so useful.
Never preceed any demonstration with anything more predictive than "watch this"
Bill Hassell
Honored Contributor

Re: bash script problem

Just a note about your script: you mentioned bash as Oracle's login shell but your script is explicitly running the HP-UX POSIX shell /usr/bin/sh. Now BASH, KSH and the POSIX shell are all based on the POSIX standards for a shell so most everything is the same. tcsh is completely incompatible with POSIX shells. So I would examine the environment inside your script with the env command (env shows exported values because it is a separate process, set shows local and exported values because it is a shell command).


Bill Hassell, sysadmin