Pass Enter key to dist-upgrade's prompt, running inside a GUI terminal on a remote machine, accessible henceforth only over SSH

I earlier had RDP access to a remote machine (a typical physical desktop PC) using which I launched a sudo apt dist-upgrade inside a GUI gnome-terminal. Since then I have lost the RDP connection and only have SSH[1]. Since there was no ‘assume yes’ in the apt command, inspecting cat /var/log/dist-upgrade/screenlog.0 over SSH has revealed that the upgrade, still running, is stuck on a prompt[2], seeking the user to hit Enter or select yes (and then hit Enter). Note that at this point dist-upgrade has been running for about an hour (excluding the await since) and has installed lots of packages.

The objective now is to pass Enter to that running dist-upgrade (or teminate the upgrade altogether but this may corrupt the system). An LLM has suggested using gdb -p pid /usr/libexec/gnome-terminal-server followed by call (int)write(0, "n", 1) where pid and executable are obtained from ps -ex | grep terminal. However that errs as No symbol "write" in current context. since No debugging symbols found in /usr/libexec/gnome-terminal-server).

Another approach is to use xdotool to generate a programmatic click. Alas, it’s not already installed on remote and installing it now isn’t possible since an update is running. This is true of all programs – at this point we have to work with what we’ve got (standard bash) and nothing new can be installed.

What to do?

[1]: Actually ‘remote:xrdp:SSHTunnel:Remmina:client’ based RDP access still works except that we are dropped into a black screen and nothing apparently can be done to wake the remote’s display.

[2]: The prompt in question is simply

#tail /var/log/dist-upgrade/screenlog.0
Package configuration

Upgrade to the firefox snap  
Starting in Ubuntu 22.04, all new releases of firefox are only available to Ubuntu users through the snap package. This package update will transition your system over to the snap by installing it.It is recommended to close all open firefox windows before proceeding to the upgrade.  

                        <-- 0:jammy -- time-stamp -- Apr/01/24 15:45:57 --          
Asked By: lineage


I’m not entirely familiar with apt, but the name of that logfile (screenlog.0) makes me wonder if the process is already running under the control of screen? If that were the case, screen -ls should show an active session, and screen -R should re-attach to it.

If the log filename is a red herring, you may be able to reptyr, which is a tool that allows you to attach an existing program to a new terminal.

Answered By: larsks
Categories: Answers Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.