Operating System - HP-UX
1823986 Members
4583 Online
109667 Solutions
New Discussion юеВ

start program in the background HP-UX problem

 
SOLVED
Go to solution
draganradosav
Advisor

start program in the background HP-UX problem

Hi all.

I need help for solving this problem.
I have a simple script (i wish to execute in the background) like:

#!/bin/ksh
su - oracle -c "whoami" > /tmp/test1.txt

When I execute it:

1) Normally (not in the background)

bash-4.1# ./test.sh
ls -altr
-rw-r----- 1 root sys 111 Aug 2 11:00 test1.txt

You can see that output output file is created.

2) In the background

bash-4.1# ./test.sh &
ls -altr
[1]+ Stopped ./test.sh

ls -altr test1.txt
-rw-r----- 1 root sys 0 Aug 2 11:04 test1.txt

Like you can see file is created, but it's empty. Also background job is stopped.

Can anybody help me to find way to execute this script in the background on my HP-UX machine (it's a HP-UX mitist1 B.11.31 U ia64).

Best regards,
Dragan


18 REPLIES 18
Dennis Handly
Acclaimed Contributor

Re: start program in the background HP-UX problem

>[1]+ Stopped ./test.sh

This means your .profile is broken, it is trying to read from stdin.

If you don't want to fix it, you can try:
./test.sh < /dev/null &
draganradosav
Advisor

Re: start program in the background HP-UX problem

Thanks,
When I have execute this, I get

#mitist2.it.telekom.yu>./test.sh < /dev/null &
[1] 23109
#mitist2.it.telekom.yu>stty: : Not a typewriter
stty: : Not a typewriter
stty: : Not a typewriter

What are my options?
I send you the profile file.

Best regards,
Dragan
Steven E. Protter
Exalted Contributor
Solution

Re: start program in the background HP-UX problem

Shalom,

Well you really aren't using HP-UX 11.31 here. You are using the bash shell, which behaves differently and sometimes less reliably than the POSIX or korn shell.

Alternatives.

nohup ./test.sh &

Try ksh or posix shell

SEP

Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: start program in the background HP-UX problem

>What are my options?

Well, did you get what you wanted in /tmp/test1.txt? If so, you are done.

>I send you the profile file.

This is HP's broken /etc/profile and you'll have to fix it. But only the login shell should invoke /etc/profile, so there may be something wrong with your .profile or whatever bash uses.

Most likely: stty erase $ERASE
If you look you'll see some threads from Bill about this:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1206345

>SEP: Try ksh or posix shell

Unfortunately these may fail the same way? :-(
rariasn
Honored Contributor

Re: start program in the background HP-UX problem

James R. Ferguson
Acclaimed Contributor

Re: start program in the background HP-UX problem

Hi Dragan:

> stty: : Not a typewriter
What are my options?

As Dennis said, there are interactive commands (namely 'tset' and 'stty') that are being invoked when your profile is read (as a consequence of the 'su - ' command.

You have several alternatives:

(1) don't use 'su -' but rather use 'su'. This form will not source (read) the profile. Hence, none of the 'oracle' environmental variables will be applied either and this may not be what you want.

(2) Condition the block of code that does the interactive commands in the '.profile' to only execute if the environment is associated with a tty:

if [ -t 0 ]; then #...interactive
...
fi

Regards!

...JRF...
Bill Hassell
Honored Contributor

Re: start program in the background HP-UX problem

su - will indeed process .profile. Because your script starts with #!/bin/ksh (the proper way to write a script by the way), it doesn't matter which shell you are using. However, su -is indeed running the Oracle local profile which would be .profile if the user oracle has ksh or sh as the login shell.

In batch (script) mode, there is no controlling terminal (tty) so commands that work fine when you login (tset, stty, tabs, ttytype, tput, and so on) will give you errors like "not a typewriter" and other errors.

To fix this situation, you must examine the oracle user's profile for any of the above commands, then protect them as James points out above. Once protected, both batch and interactive sessions will work correctly.


Bill Hassell, sysadmin
draganradosav
Advisor

Re: start program in the background HP-UX problem

Thanks to all,

I have tried first option without su - oracle, just su oracle and this is works, like you said.
Only problem is because I must always use absolute path to the names of executables i am using in the script.

Because I haven't to much experience in the shell programming how to setup this profile file so it would be valid when I am using su - oracle in the script.
I send you the profile files from both (root and oracle) user.

For root (profile)
For oracle (.profile)

When I am first log on to the server, and type: echo $SHELL
I get: /sbin/sh

You can see here that in oracle .profile I have this problematic stty erase, I have tried to comment it but nothing happened, I get the same problem.

Best regards,
Dragan
Dennis Handly
Acclaimed Contributor

Re: start program in the background HP-UX problem

>I must always use absolute path to the names of executables I am using in the script.

This is shells 101. You need to update your $PATH.

>You can see here that in oracle .profile I have this problematic stty erase, I have tried to comment it but nothing happened, I get the same problem.

If you comment it out, you should have fewer error messages. But instead of commenting it, you should fix it as JRF said. You could either add another if - fi block or fiddle with the one you have:
if [ ! "$VUE" -a -t 0 ]; then

If this doesn't fix them all, you need to fix the broken /etc/profile that HP supplies.

(Has anyone ever filed a bug report on this broken file?)
draganradosav
Advisor

Re: start program in the background HP-UX problem

Thanks,
I have changed the line
if [ ! "$VUE" ]; into if [ ! "$VUE" -a -t 0 ];

and I have the same problem.

I send you the new modificated file .profile for oracle user.

Regards,
Dragan
James R. Ferguson
Acclaimed Contributor

Re: start program in the background HP-UX problem

Hi (again) Dragan:

Yet another option is to collect the Oracle environmental variables you need into a separate file that can be sourced (read). This obviates the need to cause the '.profile' to be read when you do 'su - oracle'. Instead you would do something like:

# cat /home/oracle/oravars
ORACLE_HOSTNAME=mitist2.it.telekom.yu; export ORACLE_HOSTNAME
ORACLE_UNQNAME=tis; export ORACLE_UNQNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/db; export ORACLE_HOME
GRID_HOME=/u01/app/11.2.0/grid; export GRID_HOME
PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$GRID_HOME/bin:$PATH; export PATH
ORACLE_SID=tis2; export ORACLE_SID

# su oracle -c '. /home/oracle/oravars && /tmp/test.sh' > /tmp/test.log

Since this is an 'su' without the '-' option, the '.profile' isn't read. The switch to the oracle user is made, though and the 'oravars' file sourced and the 'test.sh' is run in that environment.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: start program in the background HP-UX problem

Hi (again) Dragan:

I meant to add that is you choose to isolate the environmental variables you need for your 'oracle' user in a separate "include-able" file as I showed above, you can remove them from the oracle's '.'profile' too. Now, you have only one palce to maintain your environmental variables but they are available however and whenever you need them. Simply substitute the "dot-space-file" line at the end of the oracle profile. Using the name I suggested before, this would look like:

. /home/oracle/oravars

This syntax causes the file to be read ("sourced" or "included") into the *current* environment. Note very carefully the dot ('.') followed by a whitespace character, followed by the file to be sourced.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: start program in the background HP-UX problem

>and I have the same problem.

Not really, you should have fewer error message. The problem is now only in /etc/profile and you'll need to fix that file too.
draganradosav
Advisor

Re: start program in the background HP-UX problem

Thanks,

Tell me is it reasonably to change the predefined root profile. Can I get some kind of consequences.
Finally what lines I need to change here (I am sending you the root profile file).


Thanks for all your time and effort.
Best regards.

Dennis Handly
Acclaimed Contributor

Re: start program in the background HP-UX problem

>Tell me is it reasonably to change the predefined root profile. Can I get some kind of consequences?

It would be better if it was reported and HP fixed it.
You already have modified the end of the file.
I don't see anything going wrong except fixing the nasty message.

>Finally what lines I need to change here (I am sending you the root profile file).

Add the following if and fi around that stty:
if [ -t 0 ]; then
stty erase $ERASE
fi
draganradosav
Advisor

Re: start program in the background HP-UX problem

Thanks,
I have changed profile fiel from /etc directory.
I send you the file.
Earlier I have changed the .profile for oracle user.

But, again when I have tried to execute the simple script:

#!/bin/ksh
su - oracle -c "whoami" > /tmp/test1.txt

in the background with

./test.sh &

I get the blank file like earlier.

Thanks,
Best regards
Dennis Handly
Acclaimed Contributor

Re: start program in the background HP-UX problem

>./test.sh &
>I get the blank file like earlier.

You must use:
>./test.sh < /dev/null &

Or you need to add that inside your test.sh script.
draganradosav
Advisor

Re: start program in the background HP-UX problem

Thanks.