3

I have a very slow connection (~10KB/s) because my mobile carrier throttled me. Now, they will send about 32KB, then stop.

I am trying to install packages through apt-get, and I noticed that I can stop (ctrl-c) then restart the install and it will pick up from where it left off.

Doing this, I can get a little bit of data, then stop it, start it, and I get a little more data, otherwise (not stopping and restarting) I have to wait for about 15 seconds before more data comes

Is there a way I can automate this and have a script stop apt-get and start again?

3 Answers 3

4

Here is a script that takes the package names as arguments and runs apt-get repeatedly, killing it after a few seconds. It runs apt-get in "download" mode, so it will only download, not install. You may want to tweak the sleep time depending on how quickly your provider throttles the download.

#!/bin/bash

me=$(basename $0)

if (($# == 0))
then
    printf "Usage: %s package [package]...\n" $me
    exit 1
fi

printf "Will install %d package(s).\n" $#
printf "This will run forever.\n"
printf "You can stop it by pressing ctrl-C when prompted.\n"
printf "If that fails, open another window and type 'killall %s'.\n" $me
read -p "Press 'Enter' to continue: "

while :
do
    timeout 3 apt-get -y -d install "$@"
    printf "Press ctrl-C within one second to stop\n"
    sleep 1
done
3
  • 2
    Why not just use the GNU coreutils timeout tool? Should be no need to reinvent the wheel.
    – user
    Commented Jun 14, 2014 at 12:03
  • Oh, very nice. Didn't know about that one. Thanks.
    – Tom Zych
    Commented Jun 14, 2014 at 12:06
  • Rewritten to use timeout.
    – Tom Zych
    Commented Jun 14, 2014 at 12:18
1

I believe it'd be better to try Ctrl + Z to suspend the process in the background. You might be able to use fg to resume once your connectivity returns.

To pause a job, press Ctrl + Z.

For restarting the job again when you get the network signals:

fg %1
0

You may want to use apt-fast, it downloads from multiple mirrors in parallel. Even if you disconnect from one it will continue download from other mirrors. You can download and setup it right from the GitHub page of apt-fast it's very well documented.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .