Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Using su in scripts

Posted on 2004-08-27
5
Medium Priority
?
1,561 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

647 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