The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
switching user from root to ordinary user sasia Shell Programming and Scripting 3 01-25-2008 06:25 PM
How to configure ssh for root user....??? jumadhiya SUN Solaris 4 02-13-2007 06:52 AM
Want to block ftp for root user jumadhiya SUN Solaris 3 02-07-2007 01:01 AM
Other than root user .Normal user is unable to create files mallesh UNIX for Advanced & Expert Users 1 06-22-2005 09:18 AM
root user hassan2 UNIX for Advanced & Expert Users 1 05-29-2002 11:15 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-24-2006
nitin's Avatar
Registered User
 

Join Date: Aug 2001
Location: Toronto, ON
Posts: 34
Stumble this Post!
Su to user from root

I'm writing a script that does many things, but it runs as a root. It does some backups etc, and then it su's over to oracle user to do some oracle stuff, this way I don't have to worry about Oracle env variables etc. Saves time, headache etc.
The thing is that, this script worked perfectly on Solaris, but it not in Linux (Redhat and Suse).
Here is a snippet:
#!/usr/bin/ksh
## doing some maintenance as root user
tar -cvf /usr/home/dir
...
## Now do some oracle stuff###
SH_LOG=/tmp/script123.log
echo "Enter user name for oracle:"
read $ORA_USER
su - $ORA_USER "sqlplus -S -L / AS SYSDBA <<\EOF >$SH_LOG
SET HEADING OFF;
SELECT GROUP#, BYTES, STATUS FROM V\$LOG;
SPOOL OFF
EXIT;
EOF"
## EOF

This above script works and changes over to oracle user in Solaris, runs my sql commands and gives me a log. When I run it in Linux, it craps out. My guess it that "su -" does not pass the variables in Linux, so it doesn't understand $ORA_USER and $SH_LOG.
I even tried "su - $ORA_USER -c -m" options, they all failed to give me the desired results. Any ideas?
Thanks in advance.

-Nitin
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-24-2006
Registered User
 

Join Date: Dec 2005
Location: London
Posts: 222
Stumble this Post!
check what is the default shell and what is the profile file loaded... i guess profile and shell settings could be the problem.. they might be different in your unix and linux box
Reply With Quote
  #3 (permalink)  
Old 10-24-2006
nitin's Avatar
Registered User
 

Join Date: Aug 2001
Location: Toronto, ON
Posts: 34
Stumble this Post!
The default shell in Linux as always is bash. I didn't write the script in bash, coz some Unix systems still don't have it. Hence, I prefer to use korn, coz it is standard across Unix. I've to run this script in a fleet of systems, so I don't want to change the shell and profile settings, all I want is that it execute my commnads in korn temporarily. Is there a way to tell what shell I want to use in 'su'.

Thanks for the reply,

Nitin
Reply With Quote
  #4 (permalink)  
Old 10-25-2006
Registered User
 

Join Date: Dec 2005
Location: London
Posts: 222
Stumble this Post!
Even in unix "su - " do not pass env variables to the new shell... it is just "su"

Code:
     To become user bin while retaining your previously  exported
     environment, execute:

     example% su bin

    To become user bin but change the environment to what  would
     be expected if bin had originally logged in, execute:

     example% su - bin
You might be using ksh in your script, but check the default shell and profile that gets loaded when you do "su" or login for oracle user...

In unix it might be loading the correct profile what you wanted but in linux it might be loading some bash profile which don't have correct settings.. compare both profile files in unix and linux
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0