Solved

Using su in scripts

Posted on 2004-08-27
5
1,546 Views
Last Modified: 2013-12-06
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
Comment
Question by:xoxomos
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:scampgb
ID: 11915418
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
 

Author Comment

by:xoxomos
ID: 11915785
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
 
LVL 15

Accepted Solution

by:
scampgb earned 125 total points
ID: 11916073
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
 

Author Comment

by:xoxomos
ID: 11916539
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
 
LVL 15

Expert Comment

by:scampgb
ID: 11920324
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This document is written for Red Hat Enterprise Linux AS release 4 and ORACLE 10g.  Earlier releases can be installed using this document as well however there are some additional steps for packages to be installed see Metalink. Disclaimer: I hav…
You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now