Linux – How to watch a terminal window remotely

centos7linuxsshterminal

I left the office earlier with an active terminal window running a script on a Centos 7 server. Now I've SSHing in from home and I want to see where it's got to. Is this possible? Can I rejoin the same terminal window from here?

Best Answer

As @Sven mentioned, the best option is to use screen or tmux. These are tools known as "terminal multiplexers". They allow you to create shell sessions which can be attached and unattached from actual logins. These tools aren't only useful to check your work from another terminal, but have other features, including sharing your session with another user and making sure that your command doesn't stop if you loose your internet connection. If you're searching for screen, you might try a search for "GNU Screen". Both of these tools are available on most Linux systems.

Typically, you would start the session, and then execute your command inside of that session. However, if you have already started the command, you might want to look up an article on moving a running command into a screen session. I wouldn't recommend trying this out the first time on something important, though. This question may be of some use:

Moving an already-running process to Screen

If you only want to check to see if the process is running, my favorite tool would be strace. This tool allows you to see each kernel call made by a process. It can take some skill to understand the output, but it should at least give you an idea if the process is running, and if you watch close enough, might catch the filenames it's opening. To do that, first, find the PID, maybe by searching through ps aux|grep yourcommand, and then:

strace -fp YOUR_PID

You can ^C to get out of that. It may not allow you to re-attach, but if you just want to know what it's doing, that should be sufficient.