* RE: logout from interactive subshell [not found] <20061012085526.GA6032@debian.inet> @ 2006-10-12 12:50 ` Com MN PG P E B Consultant 3 0 siblings, 0 replies; 20+ messages in thread From: Com MN PG P E B Consultant 3 @ 2006-10-12 12:50 UTC (permalink / raw) To: Anton Zinoviev; +Cc: bug-bash, zsh-users Mailinglist > > (1) rlogin to a foreign host > > (2) Invoke a subshell (for example because I'm setting a > Clearcase > > View) > > (3) Logout from the host > > > > Step (3) needs two steps: First I have to type 'exit' to leave the > > subshell, and then either 'exit' or 'logout' to leave the > login shell. > > On step (2) you use > > exec bash > > instead of just bash. This does not work in the general case since I don't know at the time of invoking bash, whether I will eventually just go back one level or logout completely. Imagine the following situation: rlogin foo VAR=val1 exec bash VAR=val2 Now if at this point I would decide to not logout, but just go up one level (in order to have the old value of VAR restored), there is no way to do it - typing exit would log me out *unconditionally*. Ronald -- Ronald Fischer (phone +49-89-63676431) mailto:mn-pg-p-e-b-consultant-3.com@siemens.com ^ permalink raw reply [flat|nested] 20+ messages in thread
[parent not found: <jepscxrcvq.fsf@sykes.suse.de>]
* RE: logout from interactive subshell [not found] <jepscxrcvq.fsf@sykes.suse.de> @ 2006-10-12 12:36 ` Com MN PG P E B Consultant 3 0 siblings, 0 replies; 20+ messages in thread From: Com MN PG P E B Consultant 3 @ 2006-10-12 12:36 UTC (permalink / raw) To: Andreas Schwab; +Cc: Vincent Lefevre, zsh-users Mailinglist, bug-bash > > I can't use traps here, because I know only at "exit time", whether > > I want to logout completely, or just go up one level. > > $ call_and_exit() { "$@"; if test $? -eq 42; then exit; fi; } > $ call_and_exit cleartool ... > $ exit 42 This looks clever. Maybe one should use "exit 42" too in the definition of call_and_exit to propagate the exit up, but basically a nice idea. Maybe only disadvantage that I have to think before when calling the subshell (either by calling it via call_and_exit, or by setting up suitable aliases for cleartool, bash, zsh etc., to do this automatically) - I had hoped I cut do this with an intelligent alias which gets me out of any deep nesting of subshells without having done any preparation work before. But your solution is at least cleaner than the brute-force way of finding the login shell via ps, and then killing it. Will give your idea a thought. Thanks a lot. Ronald -- Ronald Fischer (phone +49-89-63676431) mailto:mn-pg-p-e-b-consultant-3.com@siemens.com ^ permalink raw reply [flat|nested] 20+ messages in thread
[parent not found: <jefydtsvyt.fsf@sykes.suse.de>]
* RE: logout from interactive subshell [not found] <jefydtsvyt.fsf@sykes.suse.de> @ 2006-10-12 10:08 ` Com MN PG P E B Consultant 3 0 siblings, 0 replies; 20+ messages in thread From: Com MN PG P E B Consultant 3 @ 2006-10-12 10:08 UTC (permalink / raw) To: Mikael Magnusson, zsh-users Mailinglist, bug-bash > > rlogin foobar > > DO SOME STUFF > > cleartool setview myview # this creates a subshell > > DO MORE STUFF > > cleartool setview yourview # now I'm two subshells deep > > DO STILL MORE STUFF > > # Now I want to exit > > exit > > exit > > logout > > > > I would like to have a (interactive) command which does the > final two > > exits plus > > a logout for me. > > exec cleartool .... I gave "cleartool" just as an example. The point is not that I do not want the subshells to NOT be created. In contrary, I *want* to have the subshells (and they are not always created by setting a view, but sometimes simply by invoking "bash" or "zsh" respectively), because I often want to make changes in the environment, do something, and then undo the changes, i.e. go back to the previous state of the environment. But there *are* quite often cases that I am deep in a series of interactive subshells, and decide I do not want to back up one or two levels, but leave all of them and logout. So your solution doesn't solve the original problem either.... Ronald -- Ronald Fischer (phone +49-89-63676431) mailto:mn-pg-p-e-b-consultant-3.com@siemens.com ^ permalink raw reply [flat|nested] 20+ messages in thread
[parent not found: <Acbt2xG0TAhlYr+yQr+Yg16SvmfXSg==>]
* logout from interactive subshell @ 2006-10-12 8:47 ` Com MN PG P E B Consultant 3 2006-10-12 9:10 ` Mikael Magnusson ` (2 more replies) 0 siblings, 3 replies; 20+ messages in thread From: Com MN PG P E B Consultant 3 @ 2006-10-12 8:47 UTC (permalink / raw) To: bug-bash, zsh-users Mailinglist Does someone know how to deal with the following situation? Very often I do the following pattern: (1) rlogin to a foreign host (2) Invoke a subshell (for example because I'm setting a Clearcase View) (3) Logout from the host Step (3) needs two steps: First I have to type 'exit' to leave the subshell, and then either 'exit' or 'logout' to leave the login shell. Is it possible to automate this in such a way that I have to type only one command, to leave all subshells (in this case, only 1, but in general, I might be several subshells deep) AND then logout? One idea would be to use ps, locate the process to the current subshell, crawling upwards via the PPIDs to find the PID of the login shell, and kill it. But this seems to be such an awkward solution, that I thought maybe there is an easier way to do it. (Note: This posting goes to the bash and to the zsh mailing list, because this problem might be solved differently in both shells, and I'm interested in both solutions - of course a solution working in bash AND zsh would be preferable). Ronald -- Ronald Fischer (phone +49-89-63676431) mailto:mn-pg-p-e-b-consultant-3.com@siemens.com ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: logout from interactive subshell 2006-10-12 8:47 ` Com MN PG P E B Consultant 3 @ 2006-10-12 9:10 ` Mikael Magnusson 2006-10-12 9:29 ` Com MN PG P E B Consultant 3 2006-10-12 10:04 ` Vincent Lefevre 2006-10-12 18:09 ` Matthew Woehlke 2 siblings, 1 reply; 20+ messages in thread From: Mikael Magnusson @ 2006-10-12 9:10 UTC (permalink / raw) To: Com MN PG P E B Consultant 3; +Cc: bug-bash, zsh-users Mailinglist On 10/12/06, Com MN PG P E B Consultant 3 <mn-pg-p-e-b-consultant-3.com@siemens.com> wrote: > Does someone know how to deal with the following situation? > > Very often I do the following pattern: > > (1) rlogin to a foreign host > (2) Invoke a subshell (for example because I'm setting a Clearcase > View) > (3) Logout from the host > > Step (3) needs two steps: First I have to type 'exit' to leave the > subshell, > and then either 'exit' or 'logout' to leave the login shell. > > Is it possible to automate this in such a way that I have to type only > one > command, to leave all subshells (in this case, only 1, but in general, I > might be several subshells deep) AND then logout? > > One idea would be to use ps, locate the process to the current subshell, > crawling upwards via the PPIDs to find the PID of the login shell, and > kill > it. But this seems to be such an awkward solution, that I thought maybe > there is an easier way to do it. How about function rlogin() {command rlogin "$@"; exit} ? -- Mikael Magnusson ^ permalink raw reply [flat|nested] 20+ messages in thread
* RE: logout from interactive subshell 2006-10-12 9:10 ` Mikael Magnusson @ 2006-10-12 9:29 ` Com MN PG P E B Consultant 3 2006-10-12 9:45 ` Peter Stephenson ` (2 more replies) 0 siblings, 3 replies; 20+ messages in thread From: Com MN PG P E B Consultant 3 @ 2006-10-12 9:29 UTC (permalink / raw) To: Mikael Magnusson; +Cc: bug-bash, zsh-users Mailinglist > How about > function rlogin() {command rlogin "$@"; exit} > ? Hmmmm.... I don't see how this could help me. Actually, your solution would EXIT the shell I came from, after the login has finished!! So I not only have to type all the "exit"s on the remote host, I would even loose my current shell on the local host. Maybe to repeat what I would like to do: A typical application would go like this: rlogin foobar DO SOME STUFF cleartool setview myview # this creates a subshell DO MORE STUFF cleartool setview yourview # now I'm two subshells deep DO STILL MORE STUFF # Now I want to exit exit exit logout I would like to have a (interactive) command which does the final two exits plus a logout for me. BTW, I could imagine a solution using 'expect', which does the login, then hands over the control to the user, and finally if the user is done, performs the exit and logout. Ronald -- Ronald Fischer (phone +49-89-63676431) mailto:mn-pg-p-e-b-consultant-3.com@siemens.com ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: logout from interactive subshell 2006-10-12 9:29 ` Com MN PG P E B Consultant 3 @ 2006-10-12 9:45 ` Peter Stephenson 2006-10-12 10:07 ` Lloyd Zusman 2006-10-12 10:16 ` Christian Taylor 2 siblings, 0 replies; 20+ messages in thread From: Peter Stephenson @ 2006-10-12 9:45 UTC (permalink / raw) To: bug-bash, zsh-users Mailinglist "Com MN PG P E B Consultant 3" wrote: > rlogin foobar > DO SOME STUFF > cleartool setview myview # this creates a subshell > DO MORE STUFF > cleartool setview yourview # now I'm two subshells deep > DO STILL MORE STUFF > # Now I want to exit > exit > exit > logout You can turn cleartool into a function that exits the shell after running the real cleartool. cleartool() { command cleartool "$@"; exit; } Works in both shells. -- Peter Stephenson <pws@csr.com> Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: logout from interactive subshell 2006-10-12 9:29 ` Com MN PG P E B Consultant 3 2006-10-12 9:45 ` Peter Stephenson @ 2006-10-12 10:07 ` Lloyd Zusman 2006-10-12 14:58 ` Bart Schaefer 2006-10-12 10:16 ` Christian Taylor 2 siblings, 1 reply; 20+ messages in thread From: Lloyd Zusman @ 2006-10-12 10:07 UTC (permalink / raw) To: zsh-users; +Cc: Com MN PG P E B Consultant 3 "Com MN PG P E B Consultant 3" <mn-pg-p-e-b-consultant-3.com@siemens.com> writes: >> How about >> function rlogin() {command rlogin "$@"; exit} >> ? > > Hmmmm.... I don't see how this could help me. Actually, your > solution would EXIT the shell I came from, after the login > has finished!! So I not only have to type all the "exit"s on > the remote host, I would even loose my current shell on the > local host. > > Maybe to repeat what I would like to do: > > A typical application would go like this: > > rlogin foobar > DO SOME STUFF > cleartool setview myview # this creates a subshell > DO MORE STUFF > cleartool setview yourview # now I'm two subshells deep > DO STILL MORE STUFF > # Now I want to exit > exit > exit > logout > > I would like to have a (interactive) command which does the final two > exits plus > a logout for me. > > BTW, I could imagine a solution using 'expect', which does the login, > then hands > over the control to the user, and finally if the user is done, performs > the > exit and logout. With clearcase in the picture, this becomes complicated, due to the fact that cleartool automatically puts you into a subshell whether you like it or not. That's one of several reasons for why I don't like clearcase. But given that you're probably stuck having to use it, you might try something like this (assuming that you're using zsh): Put this into your ~/.zlogin: [[ ${SHLVL:-0} == 1 ]] && { export LOGINPID=$$ } Then, after your "# Now I want to exit" comment (above), do this: kill -9 $LOGINPID You can make this into an alias, if you wish. It's an ugly hack, but it may be the only thing that you can do, given that you're using clearcase. I think it will work, but I can't test it, because clearcase isn't installed on any of my machines. Good luck! -- Lloyd Zusman ljz@asfast.com God bless you. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: logout from interactive subshell 2006-10-12 10:07 ` Lloyd Zusman @ 2006-10-12 14:58 ` Bart Schaefer 2006-10-12 22:24 ` Vincent Lefevre 0 siblings, 1 reply; 20+ messages in thread From: Bart Schaefer @ 2006-10-12 14:58 UTC (permalink / raw) To: zsh-users On Oct 12, 6:07am, Lloyd Zusman wrote: } } "Com MN PG P E B Consultant 3" } <mn-pg-p-e-b-consultant-3.com@siemens.com> writes: } } > # Now I want to exit } > exit } > exit } > logout } } Put this into your ~/.zlogin: } } [[ ${SHLVL:-0} == 1 ]] && { } export LOGINPID=$$ } } } } Then, after your "# Now I want to exit" comment (above), do this: } } kill -9 $LOGINPID Yowtch. This is the right idea, but "kill -9" is way overboard; that kills the process instantly without letting it do any cleanup (like saving history), and effectively orphans the sub-shells, which you are then counting on to exit on their own. Much better would be to use "kill -HUP" which tells the shell process its terminal connection has been closed (even though it hasn't, really). Zsh will then send HUP signals to all its children [*] and exit mostly in the same manner as if you'd typed "logout". [*] Unless you have "setopt no_hup" in which case you'll need to do this a slightly different way. So here's a variation of Lloyd's suggestion: ---- # This goes in ~/.zprofile for login shells only: export LOGINPID=$$ # This goes in ~/.zshrc for all interactive shells: if [[ ${LOGINPID:-$$} != $$ ]] then function logout { kill -HUP $LOGINPID; exit } fi ---- Now if you want to stop all the shells, you type "logout", and otherwise you type "exit". If you have "setopt no_hup" and only want to kill shells, leaving other processes running in the background, modify the ~/.zshrc part: ---- # This goes in ~/.zshrc for all interactive shells: trap logout USR1 if [[ ${LOGINPID:-$$} != $$ ]] then function logout { kill -USR1 $PPID; exit } fi ---- That should cause a chain of USR1 signals to climb up to the ultimate login shell, with each shell exiting after passing along the signal. You can pick another trappable signal if USR1 is not appropriate. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: logout from interactive subshell 2006-10-12 14:58 ` Bart Schaefer @ 2006-10-12 22:24 ` Vincent Lefevre 0 siblings, 0 replies; 20+ messages in thread From: Vincent Lefevre @ 2006-10-12 22:24 UTC (permalink / raw) To: zsh-users On 2006-10-12 07:58:50 -0700, Bart Schaefer wrote: > ---- > # This goes in ~/.zshrc for all interactive shells: > trap logout USR1 > > if [[ ${LOGINPID:-$$} != $$ ]] > then > function logout { kill -USR1 $PPID; exit } > fi > ---- You need to check that the parent process is an interactive zsh shell since one can run a zsh login shell and a command in it that would run an interactive zsh. I can see at least two cases where this can happen: 1. With a text-mode login, then startx, then terminals with a zsh in them. 2. With screen. So, I suggest the following: trap logout USR1 [[ $MYPID == $PPID ]] && logout() { kill -USR1 $PPID; exit } export MYPID=$$ -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> 100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/> Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon) ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: logout from interactive subshell 2006-10-12 9:29 ` Com MN PG P E B Consultant 3 2006-10-12 9:45 ` Peter Stephenson 2006-10-12 10:07 ` Lloyd Zusman @ 2006-10-12 10:16 ` Christian Taylor 2006-10-13 12:17 ` Brian K. White 2 siblings, 1 reply; 20+ messages in thread From: Christian Taylor @ 2006-10-12 10:16 UTC (permalink / raw) To: zsh-users > A typical application would go like this: > > rlogin foobar > DO SOME STUFF > cleartool setview myview # this creates a subshell > DO MORE STUFF > cleartool setview yourview # now I'm two subshells deep > DO STILL MORE STUFF > # Now I want to exit > exit > exit > logout > > I would like to have a (interactive) command which does the final two > exits plus > a logout for me. I don't know how to do exactly what you have in mind, but I can think of two methods that may be of use to you. Both should (usually) work independent of which shell you use. The second is close to what you asked for. 1. Shortcut You can hit "^D" instead of typing exit (or logout) to terminate the current shell. If you are three subshells deep, holding Ctrl and hitting "d" three times is quite a lot faster, but you still have to keep track of how many subshells you want to exit. 2. Screen After you log into the remote box, start a screen session (simply type "screen"). Proceed to do your stuff. After you're done, hit "^A" followed by "k". Screen will ask you to confirm and then terminates all your subshells, as well as itself. To logout automatically as well, I suggest you create an alias for the command "screen; logout" and run that after login. (Screen is capable of much more, have a look at the man page if you're interested.) hope this helps, Christian ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: logout from interactive subshell 2006-10-12 10:16 ` Christian Taylor @ 2006-10-13 12:17 ` Brian K. White 2006-10-14 1:44 ` Phil Pennock 0 siblings, 1 reply; 20+ messages in thread From: Brian K. White @ 2006-10-13 12:17 UTC (permalink / raw) To: zsh-users ----- Original Message ----- From: "Christian Taylor" <cht@chello.at> To: <zsh-users@sunsite.dk> Sent: Thursday, October 12, 2006 6:16 AM Subject: Re: logout from interactive subshell >> A typical application would go like this: >> >> rlogin foobar >> DO SOME STUFF >> cleartool setview myview # this creates a subshell >> DO MORE STUFF >> cleartool setview yourview # now I'm two subshells deep >> DO STILL MORE STUFF >> # Now I want to exit >> exit >> exit >> logout >> >> I would like to have a (interactive) command which does the final two >> exits plus >> a logout for me. > > I don't know how to do exactly what you have in mind, but I can think of > two > methods that may be of use to you. Both should (usually) work independent > of > which shell you use. The second is close to what you asked for. > > 1. Shortcut > You can hit "^D" instead of typing exit (or logout) to terminate the > current > shell. If you are three subshells deep, holding Ctrl and hitting "d" three > times is quite a lot faster, but you still have to keep track of how many > subshells you want to exit. > > 2. Screen > After you log into the remote box, start a screen session (simply > type "screen"). Proceed to do your stuff. After you're done, hit "^A" > followed by "k". Screen will ask you to confirm and then terminates all > your > subshells, as well as itself. > To logout automatically as well, I suggest you create an alias for the > command "screen; logout" and run that after login. > > (Screen is capable of much more, have a look at the man page if you're > interested.) > > hope this helps, > Christian These answers come the closest to sanity in my opinion. They don't exactly do what he wants but the fault lies in the request not in the shell or anyones knowledge of how to use it. I'd have said there is no answer. Ultimately there is no way for any given process to know how far you mean when you say you want to log "all the way out" except it would/should be possible to say "all the way off this host" by talking to the daemon you logged in via. In fact that is possible but it's not garunteed to always work completely and there is one desireable level of control missing. (or, if what I'm about to describe is possible I hope to hear about it :) rlogin, ssh, & telnet all support an escape character similar to classic cu. Sometimes it's optional and not used by default, and it takes different forms between say telnet & ssh, but in some form, if desired, it's always available as an option. In the case of ssh, On a new line (or hit enter blindly if you're terminal is messed up) type ~. and you are disconnected from the ssh session. sshd on the remote host then sends a HUP to all child processes of that session and in a perfect world they all react to this in a sane manner by cleaning up shop and exiting. The problems are: 1) this isn't a perfect world and lots of apps don't die. you'll have to just try and see if you are stuck with any like that. 2) if you are connected from host to host to host, this breaks your closest connection, not your furthest one. In a perfect world again, this does end up cleanly breaking all the subsequent connections and killing all the child processes on the the whole train of hosts all in one easy shot. Maybe thats what you wanted, in which case, fine, problem solved. But if you only want to back out of your lest leg of the chain of connections and not destroy the whole chain, I don't know how to do that except by manually specifying a different escape character or sequence for each new connection, so the the escape code for one connection gets ignored and passed along as ordinary data by all the rest. The I think it's outside the shells area of responsibility to even attempt to keep track of such things. Brian K. White -- brian@aljex.com -- http://www.aljex.com/bkw/ +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++. filePro BBx Linux SCO FreeBSD #callahans Satriani Filk! ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: logout from interactive subshell 2006-10-13 12:17 ` Brian K. White @ 2006-10-14 1:44 ` Phil Pennock 2006-10-15 9:23 ` Brian K. White 0 siblings, 1 reply; 20+ messages in thread From: Phil Pennock @ 2006-10-14 1:44 UTC (permalink / raw) To: Brian K. White; +Cc: zsh-users On 2006-10-13 at 08:17 -0400, Brian K. White wrote: > rlogin, ssh, & telnet all support an escape character similar to classic cu. I believe that Mike Stroyan already offered this one -- probably a mail delay somewhere holding up parts of the thread though. > 2) if you are connected from host to host to host, this breaks your closest > connection, not your furthest one. > But if you only want to back out of your lest leg of the chain of > connections and not destroy the whole chain, I don't know how to do that > except by manually specifying a different escape character or sequence for > each new connection, so the the escape code for one connection gets ignored > and passed along as ordinary data by all the rest. Repeat the escape. If the second character is the escape character, then it's sent on as one character, so the second ssh process sees it. So assuming that it's not been changed with EscapeChar/-e, ~. for the first, ~~. for the second, ~~~. for the third, etc. For each ssh, all that matters is that the ~ be the first _seen_ character typed after a newline. More safely, ~? to see which escape sequences are offered, so that you can check it's working without logging out, or ~^Z to suspend the login. Knowing that one, for chained sessions, is a major productivity boost. Regards, -Phil ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: logout from interactive subshell 2006-10-14 1:44 ` Phil Pennock @ 2006-10-15 9:23 ` Brian K. White 0 siblings, 0 replies; 20+ messages in thread From: Brian K. White @ 2006-10-15 9:23 UTC (permalink / raw) To: zsh-users ----- Original Message ----- From: "Phil Pennock" <phil.pennock@globnix.org> To: "Brian K. White" <brian@aljex.com> Cc: <zsh-users@sunsite.dk> Sent: Friday, October 13, 2006 9:44 PM Subject: Re: logout from interactive subshell > On 2006-10-13 at 08:17 -0400, Brian K. White wrote: >> rlogin, ssh, & telnet all support an escape character similar to classic >> cu. > > I believe that Mike Stroyan already offered this one -- probably a mail > delay somewhere holding up parts of the thread though. The delay was just in my inbox. I read his message a few minutes after sending mine. >> 2) if you are connected from host to host to host, this breaks your >> closest >> connection, not your furthest one. > >> But if you only want to back out of your lest leg of the chain of >> connections and not destroy the whole chain, I don't know how to do that >> except by manually specifying a different escape character or sequence >> for >> each new connection, so the the escape code for one connection gets >> ignored >> and passed along as ordinary data by all the rest. > > Repeat the escape. > > If the second character is the escape character, then it's sent on as > one character, so the second ssh process sees it. So assuming that it's > not been changed with EscapeChar/-e, ~. for the first, ~~. for the > second, ~~~. for the third, etc. For each ssh, all that matters is that > the ~ be the first _seen_ character typed after a newline. > > More safely, ~? to see which escape sequences are offered, so that you > can check it's working without logging out, or ~^Z to suspend the login. > Knowing that one, for chained sessions, is a major productivity boost. > > Regards, > -Phil Very nice, thanks. Should have known that. cu probably does the same. Brian K. White -- brian@aljex.com -- http://www.aljex.com/bkw/ +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++. filePro BBx Linux SCO FreeBSD #callahans Satriani Filk! ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: logout from interactive subshell 2006-10-12 8:47 ` Com MN PG P E B Consultant 3 2006-10-12 9:10 ` Mikael Magnusson @ 2006-10-12 10:04 ` Vincent Lefevre 2006-10-12 10:20 ` Com MN PG P E B Consultant 3 2006-10-12 18:09 ` Matthew Woehlke 2 siblings, 1 reply; 20+ messages in thread From: Vincent Lefevre @ 2006-10-12 10:04 UTC (permalink / raw) To: Com MN PG P E B Consultant 3; +Cc: bug-bash, zsh-users Mailinglist On 2006-10-12 10:47:38 +0200, Com MN PG P E B Consultant 3 wrote: > Does someone know how to deal with the following situation? > > Very often I do the following pattern: > > (1) rlogin to a foreign host > (2) Invoke a subshell (for example because I'm setting a Clearcase > View) Is it a subshell or a second-level shell? (In the first case, $$ and $PPID remain the same.) > (3) Logout from the host > > Step (3) needs two steps: First I have to type 'exit' to leave the > subshell, and then either 'exit' or 'logout' to leave the login > shell. > > Is it possible to automate this in such a way that I have to type > only one command, to leave all subshells (in this case, only 1, but > in general, I might be several subshells deep) AND then logout? > > One idea would be to use ps, locate the process to the current > subshell, crawling upwards via the PPIDs to find the PID of the > login shell, and kill it. But this seems to be such an awkward > solution, that I thought maybe there is an easier way to do it. You don't need ps. Just get the ppid with $PPID if possible (see above) or by some other mean (see thread "Subshells and parameters" in the zsh-users archives). Each subshell can use a trap to be able to kill its parent. But bash and zsh behave differently concerning traps. Alternatively, the command that invokes the subshell could call 'exit' after it has finished (you can write a wrapper, e.g. as a shell function). -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> 100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/> Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon) ^ permalink raw reply [flat|nested] 20+ messages in thread
* RE: logout from interactive subshell 2006-10-12 10:04 ` Vincent Lefevre @ 2006-10-12 10:20 ` Com MN PG P E B Consultant 3 2006-10-12 15:04 ` Bart Schaefer 0 siblings, 1 reply; 20+ messages in thread From: Com MN PG P E B Consultant 3 @ 2006-10-12 10:20 UTC (permalink / raw) To: Vincent Lefevre; +Cc: bug-bash, zsh-users Mailinglist > > (1) rlogin to a foreign host > > (2) Invoke a subshell (for example because I'm setting a > Clearcase > > View) > > Is it a subshell or a second-level shell? (In the first case, $$ and > $PPID remain the same.) Could you kindly explain the difference? I thought it's always the same - a process (being the current shell, or cleartool, or whatever) is doing a fork, followed by an exec of the new shell. In the particular case of "cleartool setview", I don't know how it is done, but here is an example of the PIDs: $ echo $$ 25494 $ echo $PPID 25493 $ cleartool setview rofi_dft $ echo $$ 2965 $ echo $PPID 25494 So PPID changed (which I thought is very natural, since I have a new parent process now). The same effect appears if I invoke "zsh" instead of "cleartool....", so we have what you call a "second-level shell". Now I wonder what exactly would be a "subshell" then.... > Each subshell can use a trap to be able > to kill its parent. But bash and zsh behave differently concerning > traps. I can't use traps here, because I know only at "exit time", whether I want to logout completely, or just go up one level. > Alternatively, the command that invokes the subshell could call > 'exit' after it has finished (you can write a wrapper, e.g. as a > shell function). Here again, I would need to decide at the time I'm calling the subshell, what to do at the exit-time.... so not useful for me either. Regards, Ronald -- Ronald Fischer (phone +49-89-63676431) mailto:mn-pg-p-e-b-consultant-3.com@siemens.com ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: logout from interactive subshell 2006-10-12 10:20 ` Com MN PG P E B Consultant 3 @ 2006-10-12 15:04 ` Bart Schaefer 0 siblings, 0 replies; 20+ messages in thread From: Bart Schaefer @ 2006-10-12 15:04 UTC (permalink / raw) To: zsh-users Mailinglist (I'm not sure why you copied bug-bash, but I've dropped it.) On Oct 12, 12:20pm, Com MN PG P E B Consultant 3 wrote: } } > Is it a subshell or a second-level shell? (In the first case, $$ and } > $PPID remain the same.) } } Could you kindly explain the difference? A subshell is a shell started with the "( ... )" construct or by backgrounding a complex command such as a shell function or loop. It's a shell that has been fork'd, but not exec'd. A second-level shell is: } a process (being the current shell, or cleartool, or whatever) } is doing a fork, followed by an exec of the new shell. The term "subshell" is often colloquially used to refer to both, but they really aren't the same thing. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: logout from interactive subshell 2006-10-12 8:47 ` Com MN PG P E B Consultant 3 2006-10-12 9:10 ` Mikael Magnusson 2006-10-12 10:04 ` Vincent Lefevre @ 2006-10-12 18:09 ` Matthew Woehlke 2006-10-12 20:15 ` Mike Stroyan 2006-10-13 6:28 ` Com MN PG P E B Consultant 3 2 siblings, 2 replies; 20+ messages in thread From: Matthew Woehlke @ 2006-10-12 18:09 UTC (permalink / raw) To: zsh-users; +Cc: bug-bash Com MN PG P E B Consultant 3 wrote: > Does someone know how to deal with the following situation? > > Very often I do the following pattern: > > (1) rlogin to a foreign host > (2) Invoke a subshell (for example because I'm setting a Clearcase > View) > (3) Logout from the host > > Step (3) needs two steps: First I have to type 'exit' to leave the > subshell, > and then either 'exit' or 'logout' to leave the login shell. > > Is it possible to automate this in such a way that I have to type only > one command, to leave all subshells (in this case, only 1, but in > general, I might be several subshells deep) AND then logout? What about in your login (.bash_profile, etc) exporting a variable, say ROOT_PID=$$ and having a command/function/alias 'kill -s SIGHUP $ROOT_PID'? This is equivalent to killing the rlogin connection, but should clean up nicely if all you have are shells. -- Matthew "I don't question your existence -- God" (seen on a church billboard) ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: logout from interactive subshell 2006-10-12 18:09 ` Matthew Woehlke @ 2006-10-12 20:15 ` Mike Stroyan 2006-10-13 6:28 ` Com MN PG P E B Consultant 3 1 sibling, 0 replies; 20+ messages in thread From: Mike Stroyan @ 2006-10-12 20:15 UTC (permalink / raw) To: bug-bash, zsh-users > Very often I do the following pattern: > > (1) rlogin to a foreign host > (2) Invoke a subshell (for example because I'm setting a Clearcase > View) > (3) Logout from the host > > Step (3) needs two steps: First I have to type 'exit' to leave the > subshell, > and then either 'exit' or 'logout' to leave the login shell. > > Is it possible to automate this in such a way that I have to type only > one command, to leave all subshells (in this case, only 1, but in > general, I might be several subshells deep) AND then logout? This shouldn't be a shell question at all. It is an rlogin question. Type ~. to make rlogin to close the connection. The shells will all exit in response to that. (And you can do the same with ssh, which you should be using instead of rlogin.) -- Mike Stroyan stroyan@gmail.com ^ permalink raw reply [flat|nested] 20+ messages in thread
* RE: logout from interactive subshell 2006-10-12 18:09 ` Matthew Woehlke 2006-10-12 20:15 ` Mike Stroyan @ 2006-10-13 6:28 ` Com MN PG P E B Consultant 3 1 sibling, 0 replies; 20+ messages in thread From: Com MN PG P E B Consultant 3 @ 2006-10-13 6:28 UTC (permalink / raw) To: Matthew Woehlke, bug-bash; +Cc: zsh-users > What about in your login (.bash_profile, etc) exporting a > variable, say > ROOT_PID=$$ and having a command/function/alias 'kill -s SIGHUP > $ROOT_PID'? This is equivalent to killing the rlogin connection, but > should clean up nicely if all you have are shells. Excellent idea! Thank you for this suggestion. Ronald -- Ronald Fischer (phone +49-89-63676431) mailto:mn-pg-p-e-b-consultant-3.com@siemens.com ^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2006-10-15 9:24 UTC | newest] Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <20061012085526.GA6032@debian.inet> 2006-10-12 12:50 ` logout from interactive subshell Com MN PG P E B Consultant 3 [not found] <jepscxrcvq.fsf@sykes.suse.de> 2006-10-12 12:36 ` Com MN PG P E B Consultant 3 [not found] <jefydtsvyt.fsf@sykes.suse.de> 2006-10-12 10:08 ` Com MN PG P E B Consultant 3 [not found] <Acbt2xG0TAhlYr+yQr+Yg16SvmfXSg==> 2006-10-12 8:47 ` Com MN PG P E B Consultant 3 2006-10-12 9:10 ` Mikael Magnusson 2006-10-12 9:29 ` Com MN PG P E B Consultant 3 2006-10-12 9:45 ` Peter Stephenson 2006-10-12 10:07 ` Lloyd Zusman 2006-10-12 14:58 ` Bart Schaefer 2006-10-12 22:24 ` Vincent Lefevre 2006-10-12 10:16 ` Christian Taylor 2006-10-13 12:17 ` Brian K. White 2006-10-14 1:44 ` Phil Pennock 2006-10-15 9:23 ` Brian K. White 2006-10-12 10:04 ` Vincent Lefevre 2006-10-12 10:20 ` Com MN PG P E B Consultant 3 2006-10-12 15:04 ` Bart Schaefer 2006-10-12 18:09 ` Matthew Woehlke 2006-10-12 20:15 ` Mike Stroyan 2006-10-13 6:28 ` Com MN PG P E B Consultant 3
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).