Su loads .profile with argument


 
Thread Tools Search this Thread
Operating Systems AIX Su loads .profile with argument
# 1  
Old 09-24-2015
Su loads .profile with argument

Hello,

Is there any way to su another user and loading its profile with an argument.

For example I am user1 and I want to start user2

user2 .profile is interactive asking user to pass some values

I want to automate a process by switching user and if I pass an argument the interactive work will be skipped.

e.g. something like that
Code:
user1@aix $      su - user2 -c "/home/user2/.profile some_argument"

Is this possible?

Thanks

---------- Post updated at 09:42 AM ---------- Previous update was at 09:34 AM ----------

ok I found that
Code:
su user2 "-c /home/user2/.profile some_argument"

will do the job

is there any way to keep the spawned session instead of returning to the initial (user1 session)?

Last edited by vbe; 09-24-2015 at 12:01 PM.. Reason: code tags
# 2  
Old 09-24-2015
Your approach will do nothing but run .profile and return. man su:
Code:
       -c, --command COMMAND
           Specify a command that will be invoked by the shell using its -c.
           The executed command will have no controlling terminal. This option cannot be used to execute interractive programs which need a controlling TTY.

Usually, after logging in, a shell is executed to run the desired program or script. Parameters to the shell are commands to be executed, not arguments to control the session's behaviour.
# 3  
Old 09-24-2015
This is not something I would expect to work. Apparently you have a .profile designed to be a "menu" aka interactive - so "su -" is not likely to work for you here.

I would consider using a hard link and looking at $0 to see if it is .profile, or something else. If .profile, then I am logging in.

Better yet perhaps - do not use "su -", but just su -c "some command".

Or, in your case: exec su user2 -c "some command"

In "some command" you can test if you are doing a "login"/"su -" because the effective uid will not match the uid of your $LOGNAME when you do not use the "su -" syntax.

Build some tests around this behavior:
Code:
michael@x071:[/home/michael]su - root
root's Password: 
root@x071:[/root]echo $LOGNAME
root
root@x071:[/root]
michael@x071:[/home/michael]su root
root's Password: 
michael@x071:[/home/michael]echo $LOGNAME
michael
michael@x071:[/home/michael]id
uid=0(root) gid=0(system) groups=0(system),2(bin),3(sys),7(security),8(cron),10(audit),11(lp),13(dbsysadm),207(idsldap)
michael@x071:[/home/michael]

Anyway, this is not standard - think creative - and I hope this helps you move forward!
# 4  
Old 09-24-2015
First off: RudiC and MicahelFelt are right having concerns: what you attempt to do sounds not worth doing and most probably a careful analysis of your original problem (not what you think is a solution to your problem) will reveal that it can be done much better some other way. I suggest to explore such a solution.

Having said this: there is a way to do as you want - very ugly, not to be suggested but it works, at least with AIX:

Create several different user accounts by copying the line with the original user in /etc/passwd. Leave everything the same, most importantly the user ID, but change the usernames and the home directories to something distinctive. Create the mentioned home directories and give them the same filemodes and ownerships. Now put one variation of the .profile in each of these directories. Depending on into which user you su you will get the respective profile executed.

I hope this helps.

bakunin
# 5  
Old 09-24-2015
Quote:
Originally Posted by geodimo
...
ok I found that
Code:
su user2 "-c /home/user2/.profile some_argument"

will do the job

is there any way to keep the spawned session instead of returning to the initial (user1 session)?
I think you mean
Code:
su user2 -c "command"

You can simply switch to the user without a command, this opens a new interactive shell.
Code:
su user2

Also you can replace the current shell with
Code:
exec su user2

But both won't allow the calling shell to send further commands.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

launchctl loads app with icon (OS X)

We are deploying an app to our students that is running as a daemon. It keeps them from using certain software. The problem is that when we initially deploy it we don't want to require a restart. So we decided to use launchctl to load the daemon manually. When we do it this way, though, the... (4 Replies)
Discussion started by: nextyoyoma
4 Replies

2. Programming

Python pickle.loads(string)

Will this sentence return the decode of the string? Why I put a string in it but the system say: invaild load key (1 Reply)
Discussion started by: Henryyy
1 Replies

3. Shell Programming and Scripting

waiting for the files untill they loads

Hi guys, I want to know how to wait for the files untill they are loaded through ftp here the scenario is i'm searching for the files in unix directory /stage_area/loadfiles/telsims/test/ and there are 39 files daily i will recieve with names like *.todays_date i.e... (7 Replies)
Discussion started by: apple2685
7 Replies

4. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

5. Debian

Can't see anything after debian loads

Hey, I recently installed Debian on a desktop PC but when it starts I can't see anything (the monitor say no signal). I don't have any idea or even a way to figure out what going on here since I can't see anything at all not even the console. Is there something that I missed in the install, or is... (22 Replies)
Discussion started by: neur0n
22 Replies

6. UNIX for Advanced & Expert Users

How OS loads process in memory to execute ?

Hi, I was Googling to get info "How OS loads process into its memory to execute?" i mean when i execute ./<exename> , How OS exectes it? It will be better if i tell my intention, In my $LOGNAME saveral process are running, among all of these two process are my target process. Basically I... (1 Reply)
Discussion started by: ashokd001
1 Replies

7. UNIX for Dummies Questions & Answers

Adding loads of columns

Hi All, I've got file1 like this: aaa bbb ccc ddd eee fff ggg hhh kkk ppp mmm nnn and file 2 like this: aaa qqq www ddd fff ggg ggg sss zzz ppp vvv yyy and file 3 like this: aaa ggg ppp I need to match the first column of file3 and file1, then add the rest of the file 1 to... (3 Replies)
Discussion started by: zajtat
3 Replies

8. Linux

Details about the way 'gcc' compiles,links and loads?

Hi all, Can any body provide me with a link that gives the core details of the three processes(given below) in concern with 'gcc'? 1)Compiling 2)Linking 3)Loading (1 Reply)
Discussion started by: me_himanshu
1 Replies

9. UNIX for Dummies Questions & Answers

changed .profile but didnt ./.profile, yet reflected changes

hi , i added ls -F to .profile. and i need to do ./.profile for the effect to take effect BUT i didnt and YET the next day when i came to work and log in, the changes took effect. i am on aix. please explain.. thanks (4 Replies)
Discussion started by: yls177
4 Replies

10. UNIX for Dummies Questions & Answers

SCO CPU Loads

I've been asked to get a breakdown of what is consuming CPU time on our server over an extended period ? Have been asked about the CPU load on our server and I need to be able to go back to my boss and indicate what % is consumed by what process (or group of processes). I.e. 15% is database... (2 Replies)
Discussion started by: Cameron
2 Replies
Login or Register to Ask a Question