Solved

Using su in scripts

Posted on 2004-08-27
5
1,547 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
capture pcap with filtered traffic 1 66
linux pull logs and export FTP 4 71
i can not do linux commands in cygwin windows 10 6 75
video edge NVR Device Discovery Problem 4 46
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

809 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