• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1568
  • Last Modified:

Using su in scripts

Using Red Hat Linux AS 2.1

In a script, I'm trying to su to a user and execute a command that requires a parameter
su - $ORA_OWNER -c "lsnrctl start"
It never finds the lsnrctl command, i get a not found message on lsnrctl.
It works in Solaris, but not the Linux.
What do I need to do to have the lsnrctl command found?

0
xoxomos
Asked:
xoxomos
  • 3
  • 2
1 Solution
 
scampgbCommented:
Hi xoxomos,

You'll need to put in the full path to the lsnrctl program.

This is because root would have a different PATH search string.

You should be able to find out the path by logging in as root and running "which lsnrctl"

I hope that this helps - let me know if you need any further help.
0
 
xoxomosAuthor Commented:
I believe you, but this is my little test.
#!/bin/sh
ORA_HOME=/u01/app/oracle/product/9.2.0.1.0
ORA_OWNER=oracle

export ORA_HOME ORA_OWNER
date
PATH=$PATH:/u01/app/oracle/product/9.2.0.1.0/bin
echo $PATH
su - $ORA_OWNER -c "lsnrctl start"
su - $ORA_OWNER -c "lsnrctl status"


And it is still not finding lsnrctl

~
[root@dwrepository init.d]# ./testlsnr.sh
Fri Aug 27 10:58:40 EDT 2004
/opt/IBMJava2-131/bin:/opt/IBMJava2-131/jre/bin:/usr/local/sbin:/usr/local/bin:/
sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/usr/u01/app/oracle/product/9.
2.0.1.0/bin
-bash: lsnrctl: command not found
-bash: lsnrctl: command not found
[root@dwrepository init.d]#



[root@dwrepository init.d]# find / -name lsnrctl -print
/usr/u01/app/oracle/product/9.2.0.1.0/bin/lsnrctl




~
0
 
scampgbCommented:
Hmm... I take it that lsnrctl should be in /u01/app/oracle/product/9.2.0.1.0/bin ?

I don't use su myself, but I still think it's path-related

Try:
su - $ORA_OWNER -c "/u01/app/oracle/product/9.2.0.1.0/bin/lsnrctl start"

That might do the trick.

0
 
xoxomosAuthor Commented:
Well it does find the lsnrctl that way, but still does not find something.

~
#!/bin/sh
ORA_HOME=/u01/app/oracle/product/9.2.0.1.0
ORA_OWNER=oracle

export ORA_HOME ORA_OWNER
#!/bin/sh
ORA_HOME=/u01/app/oracle/product/9.2.0.1.0
ORA_OWNER=oracle

export ORA_HOME ORA_OWNER
su - $ORA_OWNER -c "/usr/u01/app/oracle/product/9.2.0.1.0/bin/lsnrctl start"


from the command line i enter ./testlsnr.sh
and get console display of :

[root@dwrepository init.d]# ./testlsnr.sh
Fri Aug 27 12:06:16 EDT 2004

LSNRCTL for Linux: Version 9.2.0.3.0 - Production on 27-AUG-2004 12:06:16

Copyright (c) 1991, 2002, Oracle Corporation.  All rights reserved.

Message 1070 not found; No message file for product=network, facility=TNSTNS-125
45: Message 12545 not found; No message file for product=network, facility=TNS
 TNS-12560: Message 12560 not found; No message file for product=network, facili
ty=TNS
  TNS-00515: Message 515 not found; No message file for product=network, facilit
y=TNS
   Linux Error: 2: No such file or directory


From command line  if i enter lsnrctl start

uid=500(oracle) gid=500(oracle) groups=500(oracle),0(root),4(adm),502(dba)
[oracle@dwrepository init.d]$ lsnrctl start

LSNRCTL for Linux: Version 9.2.0.3.0 - Production on 27-AUG-2004 12:08:39

Copyright (c) 1991, 2002, Oracle Corporation.  All rights reserved.

Starting /u01/app/oracle/product/9.2.0.1.0/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 9.2.0.3.0 - Production
System parameter file is /u01/app/oracle/product/9.2.0.1.0/network/admin/listene
r.ora
Log messages written to /u01/app/oracle/product/9.2.0.1.0/network/log/listener.l
og
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dwrepository)(PORT=1521)
))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 9.2.0.3.0 - Production
Start Date                27-AUG-2004 12:08:40
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  OFF
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/9.2.0.1.0/network/admin/listen
er.ora
Listener Log File         /u01/app/oracle/product/9.2.0.1.0/network/log/listener
.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dwrepository)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "dwprodrp.edu" has 1 instance(s).
  Instance "dwprodrp", status UNKNOWN, has 1 handler(s) for this service...
Service "dwtestrp.edu" has 1 instance(s).
  Instance "dwtestrp", status UNKNOWN, has 1 handler(s) for this service...
Service "owbnewrp.edu" has 1 instance(s).
  Instance "owbnewrp", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@dwrepository init.d]$

I'll see if the oracle people know this part.
thanx.





~
0
 
scampgbCommented:
Hmm - that's probably something to do with command-line parameters.
Doesn't make much sense though, as I assume they're in the lsnrctl script - which by this point is running as root.

You're right - the Oracle people might have a better idea there.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now