The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-24-2006
nitin's Avatar
nitin nitin is offline
Registered User
  
 

Join Date: Aug 2001
Location: Toronto, ON
Posts: 88
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
  #2 (permalink)  
Old 10-24-2006
mahendramahendr mahendramahendr is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2005
Location: London
Posts: 222
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
  #3 (permalink)  
Old 10-24-2006
nitin's Avatar
nitin nitin is offline
Registered User
  
 

Join Date: Aug 2001
Location: Toronto, ON
Posts: 88
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
  #4 (permalink)  
Old 10-25-2006
mahendramahendr mahendramahendr is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2005
Location: London
Posts: 222
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
Closed Thread

Bookmarks

Tags
linux commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0