su - user -c 'command' behaves differently


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting su - user -c 'command' behaves differently
# 1  
Old 09-14-2010
Java su - user -c 'command' behaves differently

I notice that su - user (note with dash) brings in more of the user's environment than does su - user -c 'command'. For example, if root does an su - user, and types "umask" to the prompt, one umask is displayed; yet, if instead the command is su - user -c 'umask', the value is different. I thought that if the - were used in the su command, that all of the new user's environment would be there- what am I missing? (This is HP-UX, by the way)
# 2  
Old 09-14-2010
Hi,
it depends on what shell You use, but in bash, "su - user" alone gives You an interactive shell. But the "-c" option (and some others I think) actively creates a non-interactive shell, because it reads commands from a file (more or less). Depending on shell, different resource files are read and hence different environments.

/Lakris
# 3  
Old 09-14-2010
Thanks for the info; would you happen to know of any way to force it to behave the same way as if the user logged in? Right now I have to guess at the files to explicitly source in to "fool it". Thanks again
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

'Connect' behaves differently on Solaris 11

Our application fails to run successfully on Solaris 11. The same works fine in Solaris 10. Due to which we are unable to migrate to Solaris 11. The app basically involves forking a child process, which finally connects with parent process. But on Solaris 11, it is unable to connect with parent... (0 Replies)
Discussion started by: wini008
0 Replies

2. Shell Programming and Scripting

jobs command behaving differently in script

Here is my test script: #!/bin/sh result=`jobs` echo " Jobs: "$result result=`ls` echo " LS "$result Here is the output: Jobs: LS 0 1 2 3 4 5 6 7 gcd initialize.sh #inter_round_clean.sh# inter_round_clean.sh inter_round_clean.sh~ look parallel_first_run.sh... (3 Replies)
Discussion started by: nealh
3 Replies

3. Linux

Does a network switch behaves as webserver

Hi, I have a question on web servers and network switches. Why a network switch should support certificate management, that means generating public and private keys... installing a certificate etcetra. Regards Chaitanya. :b: (4 Replies)
Discussion started by: chaitus.28
4 Replies

4. Shell Programming and Scripting

why Cron behaves different ?

Hi, i have script called script.ksh script.ksh --------- echo "Narayana" >$HOME/script.log echo "$0" |sed 's/.ksh//' >>$HOME/script.log My question is: -------------- when iam executing on the prompt it is giving good results what we have expected... example on the prompt:... (4 Replies)
Discussion started by: lnviyyapu
4 Replies

5. Shell Programming and Scripting

Executing a script from CRON behaves differently than terminal

Hi have a script which transferers from Microsoft server to Linux box. The scripts(ksh) is on Linux box. If I run script from terminal, it transfers files to directory. Where as If I run script from CRON. It does not. Here is the log of both: Terminal execution log:... (2 Replies)
Discussion started by: dipeshvshah
2 Replies

6. AIX

Command behaves different in script and on prompt

$cat /tmp/tuxob.lst udi ***** jim 10 ant 19 ibm ***** $ input=`head -1 /tmp/tuxob.lst | awk '{print $NF}'` $ echo $input The output I am expecting is '*****'. But It is showing me the available files of current directory. When I run the command head -1 /tmp/tuxob.lst | awk '{print $NF} ... (3 Replies)
Discussion started by: panchpan
3 Replies

7. Shell Programming and Scripting

mpack behaves abnormally

Hi, I was using mpack to send mails using cronjob with attachments. It was working perfect. But recently it's behaving strangely. Its sending the mails without any error message but the mail is not getting delivered. The code I was using: /usr/local/bin/mpack -s "$SUBJECT" -d $MSGBODY... (0 Replies)
Discussion started by: itesh.dash
0 Replies

8. Windows & DOS: Issues & Discussions

Awk script in DOS and Linux behaves differently :(

Hi, I have an awk script which performs simple operations of variable assignments and finally printing the variables in custom form. BEGIN {FS=OFS="\n"} { v1=substr($0,1,15) v2=substr($0,16,200) v3=substr($0,216,20) print v1 "|" v2 "|" v3 } The input file being processed... (2 Replies)
Discussion started by: vidyak
2 Replies

9. Shell Programming and Scripting

simple CSH Script behaves differently on Solaris and RedHat Linux

I have a simple csh-script on a Solaris Workstaion which invokes the bc calculator: #!/bin/csh set shz=2 set zshift=5 set shzp=`bc -l <<END \ scale = 3 \ -1. * $shz + $zshift \ END` echo $shzp The result ($shzp) in this case is 3 (-1*2+5). It works fine on Solaris 8. ... (2 Replies)
Discussion started by: two reelers
2 Replies

10. Shell Programming and Scripting

Script behaves different when run from cron vs. manually

Hey all, Just wanted to get some input on a script I am using to import files into a MySQL database. The process is pretty simple: my main server exports these files and FTPs them. I have a script that FTPs them to the machine running that runs this script. The FTP script runs without issue... (2 Replies)
Discussion started by: billtwild
2 Replies
Login or Register to Ask a Question