Quit vim externally without kill command - vim

I was booted from an ssh session while in a vim session. Apparently, the vim session is still open, but I cannot seem to access it. Also, when I try to kill it, I don't have permission. I know the pid's of the vim sessions but I can't find the right command to either re-enter those sessions or quit them.

Related

Resume gdb session after parent shell terminated

I was running gdb over an SSH shell. After a while the shell disconnected due to being idle. On reconnecting I see the gdb instance still running.
How do I take control of the running gdb instance?
Can I start a new gdb instance and take over the session from the running gdb instance?
Note: This is not about keeping the SSH session alive. This is more about taking control of gdb from another shell instance. Regardless of whether it is running from SSH or locally.
You probably can't do anything with the gdb that is already running. It probably no longer has a controlling tty at all. What you probably want to do is kill it and then start a new gdb process, but do it inside a program like tmux or screen. If you do that, then if/when you get disconnected you can easily reattach to the tmux/screen session any time. Just check out the manual for those programs. They do pretty much the same thing. I think tmux is a little more powerful.

Automatically close PuTTY when connection is lost

I have a script in bash, running multiple PuTTY sessions.
For example, I open the connection to run a couple of commands, when it finishes it saves the values, closes the session, opens a new session and runs a couple more.
This script is supposed to run for 60 hours, more or less, so i need to have everything automated.
My issue is, when the PuTTY session is open, and connected to the device i need, if at some point the device reboots (don't know why it reboots, it just does), a window in putty appears saying the connection was terminated (obviously). The problem is that the window stays open until I press the "ok" button. So my script just stops there until some manual interaction with the PuTTY session.
Is there a way to automatically terminate the PuTTY session if a disconnection happens?
Thank you for your help, if you need some more information just let me know!
regards
PuTTY is not intended for automation.
Use PLink (PuTTY command-line tool). It's a console application, with the same command line arguments as PuTTY, so the transition should be easy.
Though setting "Close window on exit" to "Always" does work (even if you claim it does not).
See the "Close Window on Exit" option in the Session panel.
Documentation

Is there a way to have Vim reconnect to a different X server?

I am using Vim inside tmux over an ssh connection on a remote machine. I access the remote server from several locations including work and at home. This usually causes stale $DISPLAY variables and associated problems, most of which I have resolved except for one:
If I have a vim session already opened, is there a way to change which X server it is connected to without closing and re-opening it? I need to be able to do this so I can copy snippets of text from Vim using the X clipboard. I normally keep multiple vertical splits, linebreak and line numbers on, so doing this through tmux is usually a giant hassle and would prefer to do it with vim.
You can use xpra to display a running X11 program (specifically, vim) on different X11 servers.
This program functions for X11 programs like GNU screen or tmux do for terminal programs. xpra provides an X server for running programs and itself acts as an X client for the X server for the user's display.
You mention that you are running vim through tmux; you should maybe run vim outside of tmux and use xpra directly. As far as I know the program has to be run through xpra from the start.
There's a relatively new command called xrestore which does this:
:xrestore :0
https://groups.google.com/g/vim_dev/c/G54XTJHAqXI
https://github.com/vim/vim/issues/3649
If the sole purpose of using X is to transfer large amount of text, consider using scp instead.
From within vim mark the lines you're interested in and do :w /tmp/foo
From a shell (or suspend vim using ctrl-z ; bg) do
scp your_username#remotehost.edu:/tmp/foo /some/local/directory
I added the following line to ~/.tmux.conf on the server and reloaded the tmux sessions there. This one-liner does the trick of automatically attaching to the local X-server when I connect to the tmux-session from multiple local clients using SSH. Each local client has its own X-server (X410 in my case).
set-option -g update-environment " DISPLAY"
How it works? According this post, the line is supposed to refresh the $DISPLAY variable for all panes. Here is another related post.
Setup: all my local clients are Windows 10 machines, running WSL (Pengwin distro as WSL2). My X-server is X410 downloaded from the Windows Store. The server that hosts the Tmux+vim sessions is a Linux Mint machine. On the server, the Tmux version is 3.3a.
Per my workflow, this means a lot. Especially that I don't have to repeat the following procedures: 1. SSH from another local machine; 2. Finding that clipboard won't work; 3. Save the work, exit Vim; 4. Start a new pane in the current Tmux session, and 5. Start Vim again, trying to load back to where I was.

Conitue ssh from previous state

I'm accessing through ssh to a linux box. I was simply updateing the packages with yum update. I then disconnected but when I connnected again with ssh using the same account I couldn't now if the update process had already finished.
How can I know the status of tasks I've started before disconnecting when I reconnect to the server?
Thanks in advance
Use screen <program>. At this point you can either disconnect or hit CTRL-A, CTRL-D and do other things. You can later re-attach your session to the screen running your program by screen -r.
Specifically if you want to save the state of your shell between ssh sessions you can just run screen and then run your programs.

re-initialize / reconnect a terminal after network interruption

I have what is probably a very simple terminal related question.
I'm running Ubuntu 8.10 Intrepid Ibex, using Gnome, and I often open a terminal-based
ssh session only to have it dropped at some point later on. Once the session is dropped the
terminal becomes unusable, obviously because the network connection has been dropped.
Is there a way to re-initialize the session, or even revert to a working local terminal?
Under Windows, using putty, when this happens I can right-click and select restart session,
and do not need to open a new terminal, however under linux my lack of understanding on this
subject has lead me to always close the defunct terminal, and restart a new one from scratch.
I'd like to learn a new and useful trick if there's one out there.
Also, I found the following post which is worded very similarly to mine,
Automatically (or more easily) reconnect to a screen session after network interruption
reconnect-to-a-screen-session-after-network-interr
however, as far as I can tell, this is a different topic.
You want to use your SSH escape. By default it's '~', and ~. will terminate your connection.
The question you linked to is about screen, which is useful for resuming your remote session once you use the escape character to kill your local ssh process and reconnect.
First use ~. to disconnect your ssh connection locally. This gets you back to a working local terminal. You could also you another terminal to kill the appropriate ssh command.
In order to keep your remote state you should use screen as previously suggested.
I recently found out about mosh which is a interesting UDP-based resumable shell client. It uses ssh to initialise the connection, and probably needs mosh installed at the server (and UDP access between the client and server), however it can recover from disconnections and IP changes of the client.
To have your local terminal usable again, you can use the reset command.
To run a command in a virtual terminal you can attach/dettach you can use screen or tmux. Typical usage for screen:
$ screen -S somename
screen$ some-console-command
...
^ad
You detach from screen by typing ctrl+a then d
Then you can list the session and attach to it
$ screen -ls
$ screen -dr somename
screen$

Resources