A second bash to auto-run as non-root user

Thread Solved

Join Date: Jul 2008
Posts: 36
Reputation: lehe is an unknown quantity at this point 
Solved Threads: 0
lehe lehe is offline Offline
Light Poster

A second bash to auto-run as non-root user

 
0
  #1
Mar 6th, 2009
Hi,
These days I have to install a higher version of bash under my $HOME on my office server. I hope to make the new bash automatically run both when I ssh to my server and when I boot into my office computer which loads my $HOME on the server. I don't have root access to the server, so I added into ~/.bash_profile that:
Shell Scripting Syntax (Toggle Plain Text)
  1. SHELL='${HOME}/bin/my_new_bash/bin/bash'
  2. exec $SHELL

The new bash starts automatically if I ssh to the server, however, if I try to login into my office computer, I will not be able to with the following error:
Your session only lasted less than 10 seconds. If you have not logged out yourself, this could mean that there is some installation problem or that you may be out of disk space. Try logging in with one of the failsafe sessions to see if you can fix this problem.
I can login successfully if the line "exec $SHELL" in .bash_profile is commented.

I was wondering if there is some way to make the new bash start automatically without the login error when login into my office computer?
Thanks!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: A second bash to auto-run as non-root user

 
0
  #2
Mar 6th, 2009
Hey there,

Sometimes it will work if you just replace your exec call with a simple direct call, so instead of:

exec $SHELL
just do

$SHELL
<-- Since you're not exec'ing (i.e. replacing the current process with your new process, you shouldn't get the session timeout error since you'll just be running your new bash on top of the old one. The downside is you have to exit the shell twice to logout.

And, since it works for your ssh, you can ssh in and check the status of the $- variable. Note what that is and then change your profile to simply run the new shell rather than exec it and check teh value of the variable as well. This will show you what options are automatically set when you login with bash via ssh versus direct login. If they're different, you can add a simple if-conditional in your profile to determine whether to exec your new shell or just run it straight-up and suffer with the double exit

Just FYI, you can expect to see this kind of output when you query the $- built-in:

echo $-
himBH
the output should be different for both connections.

Best wishes,

Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 36
Reputation: lehe is an unknown quantity at this point 
Solved Threads: 0
lehe lehe is offline Offline
Light Poster

Re: A second bash to auto-run as non-root user

 
0
  #3
Mar 9th, 2009
Hi Mike,
Removing "exec" works! Thanks a lot! Sorry for a little late, for I can come back to my office only on working days to have a try.
It seems that log out twice doesn't happen to me? I only need Ctrl+ALT+Backspace once to log out.
Regards
Last edited by lehe; Mar 9th, 2009 at 12:14 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: A second bash to auto-run as non-root user

 
0
  #4
Mar 9th, 2009
Hey,

Glad I could help. In the process, you taught me a cool trick. I never knew you could do that... all those years.... exiting over and over again just to get out of a terminal session. It figures

Thanks, Lehe

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC