6

I have started downloading my ISO's etc directly to my fileserver using wget. After I close the ssh session, how can I check back on the download process?

Scenario: I start the download, then shut down my computer. The next day I ssh into the server and want to see if the download is still active, complete or has been interupted.

9

If you run wget and close the terminal or terminate your ssh session , it will terminate the wget process too. You need to run wget and keep it running even after the session is closed.

For that purpose there are many tools.

   wget -bqc http://path-to-url/linux.iso

You will see a PID on screen:

Continuing in background, pid 12345.

Where,

-b : Go to background immediately after startup. If no output file is specified via the -o, output is redirected to wget-log.
-q : Turn off Wget’s output aka save disk space.
-c : Resume broken download i.e. continue getting a partially-downloaded file. This is useful when you want to finish up a download started by a previous instance of Wget, or by another program.

The nohup command

You can also use the nohup command to execute commands after you exit from a shell prompt. The syntax is:

   $ nohup wget -qc http://path-to-url/linux.iso &

   ## exit from shell or close the terminal ##
   $ exit

The disown bash command

Another option is to use the disown command as follows:

      $ wget -qc http://path-to-url/linux.iso &
      [1] 10685
      $ disown wget
     $ ps
        PID TTY          TIME CMD
        10685 pts/0    00:00:00 wget
        10687 pts/0    00:00:00 bash
        10708 pts/0    00:00:00 ps
     $ logout

The screen command

You can also use the screen command for this purpose.

  • I don't have the problem of wget halting after closing my ssh session. Until now, I can sudo-monitor the download by viewing the target folder in my file manager and seeing the file size grow. This however, doesn't say whether the download is still in progress (except for refreshing the view and seeing the file size jump) or if the download was interrupted and needs restarting. – Andrew Heath Dec 29 '15 at 14:44
  • Yet another way (just for completeness) would be echo 'wget ...' | at 'now + 1 minute' (on systems which run atd – some systemd-based ones don't do that anymore by default). In this way, there is no connection whatever between the download and the calling shell, since the download is started in one minute by the timed execution daemon. – Ulrich Schwarz Dec 29 '15 at 17:50
  • These look like nice ideas. However they seen to be centred around providing an output that disappears once the terminal window is closed! I am looking to be able to jump back in after a NEW terminal session is started. – Andrew Heath Dec 30 '15 at 14:36
3

Go to download directory and type

tail -f wget-log 
  • 1
    You should specify that this will only work if run in the background without the quiet parameter, but it is not a bad idea. – Julie Pelletier Aug 23 '16 at 5:44
0

You can also use tmux (which is a bit like screen) but I think is easier to use.

sudo apt-get install tmux
tmux new -s <session-name>

then run you script in the session press control + b + d to detach

when you want to get back the terminal simply do

tmux a

The advantage is that you can check back easily if anything has gone wrong but if you want to download lots of simultaneous files, maybe its easier to check the log

-1

After a bit of Googling, I found an answer with the discovery an app called Screen.

After installation on the server (sudo apt-get install screen), you SSH into the server and open a screen session on the server with screen -S SESSION_NAME (replacing SESSION_NAME with any name you like). Then you run WGET and once the download is running, exit the session with CTRL+a, then press d (to detatch from the session. You can run multiple sessions (with different names) at the same time.

After re-login at a later date, you can check on your processes by SSHing into the server and reopening the screen session on the server with screen -r SESSION_NAME (to reconnect to the session).

Once the session is finished with, kill it with CTRL+a, then press k (to kill the session).

It's like having a virtual terminal within your virtual terminal.

  • The screen has been refereed in first answer as well – Ijaz Ahmad Khan Jan 26 '16 at 20:58
  • You should award points to those that take time to answer your question, even if you find the answer on your own. That is the ethical code of S.O. and largely what the S.O. economy of points revolve around. – Lennart Rolland Aug 21 '18 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.