Operating System - HP-UX
1834150 Members
2385 Online
110064 Solutions
New Discussion

shell script question - redirect standard output

 
SOLVED
Go to solution
Ridzuan Zakaria
Frequent Advisor

shell script question - redirect standard output

Hi,

I am having the following problem in redirecting message to stdout.

Senario 1:
Here is my script and it works fine if I logged as user A and run the script.
----------------------------
TTY=`tty`

. /oracle/utils/orasid rendb

echo test start > $TTY

(sqlplus /nolog <connect system/manager
host echo hai > $TTY
exit
EOF
) > $HOME/sqllog.log

echo test finish > $TTY
---------------------------
The output is
-------------
test start
hai
test finish
------------

Senario 2:
But it doesn't work if I logged on as user A then change user to ' su - B' because my terminal device (tty) is own by user A.

Output:
/bin/sh: /dev/ttyp2: Cannot create the specified file.


Then I have tried to use file descriptor

exec 5>&1
. /oracle/utils/orasid rendb

echo test start >&5

(sqlplus /nolog <connect system/ora99dba
host echo hai >&5
exit
EOF
) > $HOME/sqllog.log

echo test finish >&5

Output:
test start
/bin/sh: /dev/ttyp2: Cannot create the specified file.
test finish.

With the above method and still having the problem to display message 'hai' in the sql block above.

The above script will be used in Senario 2. Does anyone know how to go about resolve the issue.

Thanks.

quest for perfections
4 REPLIES 4
harry d brown jr
Honored Contributor

Re: shell script question - redirect standard output


REmove the redirection to $TTY

live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor
Solution

Re: shell script question - redirect standard output


You could also just redirect to /dev/tty

live free or die
harry
Live Free or Die
.Olav Kappert.
Advisor

Re: shell script question - redirect standard output

You could also just redirect to /dev/tty

Instead of using $TTY, redirect the output to /dev/tty.

Good luck.
Olav Kappert
Ridzuan Zakaria
Frequent Advisor

Re: shell script question - redirect standard output

Hi,

Thanks everyone for your feedback. I have changed my script to use /dev/tty.

quest for perfections