8

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.

4 Answers4

14

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.

Ijaz Ahmad
  • 7,202
  • 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
  • http://fitnr.com/showing-file-download-progress-using-wget.html – Ijaz Ahmad Dec 29 '15 at 15:06
  • 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
  • @AndrewHeath ps aux | grep wget | grep -v grep shows active wget processes. As for a way to check the progress percentage, if you start without -q and you used nohup then the progress will be printing in the nohup.out file. – Captain Man Jan 23 '20 at 17:14
  • @IjazAhmadKhan Does doing wget -b (without using nohup) keep it running even if the session is closed? I'm having trouble following. – Captain Man Jan 23 '20 at 17:16
5

Go to download directory and type

tail -f wget-log 
Archemar
  • 31,554
Joker Kyaw
  • 51
  • 1
  • 2
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 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. – Mr. Developerdude Aug 21 '18 at 12:50
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