Downloading large file on remote host. Then close ssh connection - bash

I am trying to download a stackoverlfow dump of all posts to a remote server (actually a container on a remote host). Now as you can image the dump is large (11G). I want to start a download and then be able to exit my SSH connection to the remote host.
I have looked at tmux but it's confusing.
I know wget https://archive.org/download/stackexchange/stackoverflow.com-Posts.7z will work but I will have to stay connected for the duration of the download.
Does anyone know how I can use tmux to solve this problem?

If I've correctly understood you situation, using nohup to launch the command will do the trick.
nohup wget https://archive.org/download/stackexchange/stackoverflow.com-Posts.7z
This will prevent the killing of the wget process when the shell terminates.
You can connect via SSH, execute the above command and exit. It will keed downloading by itself.
By the way: Tmux stands for Terminal Multiplexer and it's not related to the life cycle of a process.

Related

Can I locally retrieve the cwd of a remote shell on the other side of a ssh connection?

Lets say I run the following commands:
user1#172.50.50.50:~$ ssh user2#172.51.51.51:/Documents
user2#172.51.51.51:~/Documents$ cd ~/Desktop/
user2#172.51.51.51:~/Desktop$ pwd
/home/user2/Desktop
Is there a way for me to get the path /home/user2/Desktop from the pid of the ssh process from another process on 172.50.50.50?
I thought maybe it would be somewhere in /proc/<SSH PID>/ but I can't figure it out.
No, you can't.
The SSH client has no knowledge of the server's working directory. It's not transmitted anywhere in the SSH protocol. In fact, there's no need for the SSH server to know the working directory of the process (group) that it's transferring characters to and from.
The only way to get what you want is to independently access the server host, locate the corresponding sshd process and the particular child process, then interrogate that child.
It's not trivial to even know which child process is relevant - you may have three or four shells in foreground, background or stopped, and perhaps some editors and other application programs, all with different working directories. Which one of those is required?
If you have sufficient permission on the server and know the ssh pid, you can do:
ls -l /proc/<SSH PID>/cwd
the /proc/<pid>/cwd is a symlink, link to the process cwd.

Is there a way to attach lftp to a lftp process running another machine?

When you exit lftp it keeps running in the background and the attach command is used to attach lftp to that process once again if you need to but I'm wondering if there is a way to attach lftp to a lftp process running another machine to which you have ssh access? An example would be great.
It's easy to do when provided with ssh access. Just do
ssh user#host "lftp -c attach"

How to exit from ssh session and execute commands on the last shell from a shell script?

I'm trying to write a small shell script. It should exit from the current ssh session but after that execute commands on my local computer. I don't know if thats even possible. The situation is the following: I modify a project, test and build it on my buildserver. When I start the script I would be on my buildserver and I would have modified and tested the project. Now I want a script to speed of the process of compiling the project and installing it on my local computer. To do this manually I would basically do something like the following:
user#buildserver:~$ ./build project
user#buildserver:~$ exit
user#localcomputer:~$ scp buildserver:/home/user/project/binary /tmp
user#localcomputer:~$ /home/user/install /tmp/binary
The only thing I got working so far is to exit from the ssh session by calling logout in s shell script.
A script running on a remote computer you’re connected to through SSH cannot execute commands on your computer without making a further SSH connection to your computer (which may not be an option if you’re behind a NAT or do not have an SSH server running).
A possible alternative may be to have a script on your computer that runs the shell script on the remote computer through SSH; once that remote script has finished, the local SSH client will exit and your local script can continue exiting whatever local commands are desired.

Detach program from SSH connection on a windows

I need to log in to a Windows server via SSH through a local Python (2.7) script, start a script on the server and then disconnect the SSH connection, so that the local script can continue to run.
As of now, I am using fabric, and the local script will not continue before the remote script is done and the SSH connection is closed.
I have read on a range of forums, but it seems to my (admittedly inexperienced) eyes that most replys use unix commands. I need to be able to log onto a windows machine however.
What can I do?
Thank you very much in advance!
Does this help you? You can write a batch script that'll start in the background:
Running Windows batch file commands asynchronously

VNC Bash Problem

I'm having a curious problem with a little script to make a VNC connection to a remote host. The script just makes an SSH tunnel for the VNC session and then opens the viewer. It's only two lines, and when copied into the shell manually, it works fine. However, invoking the script causes the VNC viewer to fail with this error:
main: unable to connect to host: Connection refused (111)
Here's the script:
#!/bin/bash
ssh -N -L5903:localhost:5903 username#example.com &
vncviewer :3
The tunnel lives throughout the process, so that isn't the problem. Neither is permissions -- the same error occurs when the script is run as root. I've got public key authentication set up, so it's not that ssh is requesting a password.
What am I missing? The commands work when typed in the shell!
Thanks in advance.
Most likely the vncviewer command is being executed too quickly after the ssh command. Try putting
sleep 3
between those two commands to allow time for the port forwarding to be set up.

Resources