Your approach will do nothing but run .profile and return. man su:
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.
Location: on the road for work; home is private time
Posts: 456
Thanks Given: 10
Thanked 108 Times in 100 Posts
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:
Anyway, this is not standard - think creative - and I hope this helps you move forward!
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.
is there any way to keep the spawned session instead of returning to the initial (user1 session)?
I think you mean
You can simply switch to the user without a command, this opens a new interactive shell.
Also you can replace the current shell with
But both won't allow the calling shell to send further commands.
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)
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)
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)
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)
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)
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)
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)
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)
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)