29

Let's say I start in my local account:

avindra@host:~>

then I switch to root:

host:~ #

Then I switch to oracle:

[ oracle@host:~]

Is there a way for me to drop back into the root shell (the parent), without logging out of the oracle shell?

This would be convenient, because the oracle account does not have sudo privileges. A typical scenario with oracle is that I end up in /some/really/deeply/nested/directory, and all kinds of special environment variables are set in particular ways.

Here comes the problem: I need to get back into root to touch some system files. Yes, I can log out of oracle to get back to root, but at the cost of losing my current working directory and environment.

Is there a way to "switch" to the parent shell using known conventions?

  • If you are using a gui desktop, you can just open another terminal window or tab or even switch to another virtual console. If not, use screen as stated in one of the answers. – Joe Dec 26 '14 at 19:55
  • I'll look into screen, I haven't used it before. As for tabs, I prefer to use one tab for host. I find a workflow that entails multiple tabs per host to be cumbersome. I do a lot of work in clustered hosts / distributed systems, so even having one tab per node in the cluster can get confusing. In my mind, one tab = one discrete host. – Avindra Goolcharan Dec 26 '14 at 20:08

3 Answers3

41

You can simulate a CTRL-Z (which you normally use to temporarily background a process) using the kill command:

[tsa20@xxx01:/home/tsa20/software]$ kill -19 $$

[1]+  Stopped                 sudo -iu tsa20
[root@xxx01 ~]# fg
sudo -iu tsa20
[tsa20@xxx01:/home/tsa20/software]$

bash just traps the CTRL-Z key combination. kill -19 sends SIGSTP to the process which is effectively the same thing.

Bratchley
  • 16,824
  • 14
  • 67
  • 103
3

Csh, bash, ksh, zsh, have a suspend builtin command (or alias, in ksh) that does exactly that. This command is mostly equivalent to sending a TSTP signal to the shell; bash and zsh do a bit of additional signal handler and juggling, and in these shells the suspend command works even if the shell is currently ignoring TSTP.

You can also send the signal to the shell manually with kill -STOP $$.

0

I would also suggest that you could use (install if needed) a program called [screen][1] that let's you have multiple terminal windows open. It was designed for TTYS so it works just fine without needing X. You can use keyboard shortcuts to switch between terminals and disconnect and logout, leaving your terminals still running, then log back in and reconnect to them.

I believe most Linux distributions have packages for this program, and I have used packages on Solaris for it. Worst case of course is you can install from source.

qneill
  • 113