Skip to main content

How to use your unlimited quota 2AM-8AM

Fun with BASH. Disclaimer: this may contain typoes, thinkoes, etc. Use (or don’t use) entirely at your own risk. The intent is to be educational here rather than subject to chapter-&-verse unquestioning acceptance. If the clock on the computer running this is inaccurate by more than five minutes, the downloads may (partially) take place from your monthly quota (in which case install rdate & aim it at a suitable time server, then install/use hwclock to update the PC’s battery-backed clock).

Behold, the grabqueue.sh file:

#!/bin/sh
for list in pending/*; do
    N=$(wc -l $list | sed -e 's/ .*$//')
    for url in $(seq $N); do
        L=$(tail -n +$url $list | head -n 1 -)
        if [ "$L" != "" ]; then
            wget -c "$L"
        fi
    done
    rm -f $list
done
rm -f /tmp/grabqueue.pid


Run this (in cron) at 02:05 (a little clock slackness):

#!/bin/sh
cd /path/to/download/directory
sh grabqueue.sh &
echo $! >/tmp/grabqueue.pid


Run this (in cron) at 07:55 (again, clock slackness):

#!/bin/sh
if [ -f /tmp/grabqueue.pid ]; then
    kill $(cat /tmp/grabqueue.pid)
    rm -f /tmp/grabqueue.pid
fi


Discussion: put the URLs of whatever you wish to fetch within text files inside the pending subdirectory within your downloads directory, one URL per line. Empty lines within these files are ignored.

The “-c” option (to wget) causes it to continue an existing download (or start a fresh one if the file does not yet (locally) exist). This means that attempting to download a file you already have will occupy a fraction of a second, plus little or zero traffic.

The script deletes each file full of URLs after the last URL in the file has been downloaded from.

The $! phrase in BASH is replaced with the PID (Process ID) of the most recently spawned sub-process. The first cron job launches the script, then records the PID within a temporary file. The second cron job (if said file still exists) kills the process so listed, then deletes the temporary file. Anything not completely downloaded at that point will be resumed during the next morning, until each download is completed.

Within the script, $list is the name of the URL-list file currently being processed. $L is the line containing a URL which is being downloaded.

To download videos, ensure that you have the URL for the video file itself (which typically ends with .mpg or .flv or .mp4), rather than the URL of the web page upon which the video is presented (so typically not ending with .html or .asp or .htm or .php).

Comments

kundip@hotmail.com said…
Here is my attempt
#!/bin/sh
for list in /home/k~p/grabqueue/*; do
N=$(wc -l $list | sed -e 's/ .*$//')
for url in $(seq $N); do
L=$(tail -n +$url $list | head -n 1 -)
if [ "$L" != "" ]; then
wget -c "$L"
fi
done
rm -f $list
done
rm -f /tmp/grabqueue.pid

I put a file named "list" in /home/k~p/grabqueue
Do I need
rm -f /home/k~p/grabqueue/list
as last line so it does not download over and over each night?
Leon RJ Brooks said…
Brett, $list is a variable name, not a filename. Within the “for” loop, it represents each text file in the /home/k~p/grabqueue directory, one file at a time.

Each file is read, each non-empty line in the file is treated as a URL & downloaded.

YouTube URLs will only fetch the page around the video, rather than the video file itself, hence the need for the grabyoutube.sh mucking around.

This process is only useful if your ISP has a no-quota download period (which ExeTel does from 02:00 to 08:00).
Unknown said…
Thanks I have 20 gig off-peak 95% unused to date usually use "at" command
and wget with a text file. Prone to running past 8am if links are slow to download. The best would be for me if as each line of text file is done it is deleted then at 8am something to kill wget. Then I could grab the rest on following nights.
Leon RJ Brooks said…
Yo, that’s what the second cron job does: kills off the downloading process.

One amendment needed for the grabyoutube.sh script is that ${RANDOM} fails, (resolves to an empty string), it needs to be $RANDOM instead (to resolve to a random number).

Popular posts from this blog

An Open and Shut response to Darl McBride

Hi, Darl. I see you’re being dishonest again . It’d be really nice if you could shoot straight for a change, but I think Kerry’s Dad will be selling snowplows in Hell first. Three years ago, when I first joined The SCO Group, we focused the company on the area that was most profitable and provided the most benefit to customers, investors, resellers, developers and employees: UNIX No, you focused the company on suing people, which was most profitable to lawyers and provided some golden parachutes for your buddies. People thought we were crazy. They were right. But since SCO owns the UNIX operating system The SCO Group does not own UNIX® in any sense of the word. The Open Group owns the UNIX trademark, definition and other rights , The SCO Group does not. The SCO Group doesn’t even own the UnixWare® or OpenServer® code, the rights to those are held by Novell and TSG use them only by permission and under certain conditions — which they have violate...

5x7 text dot-matrix in five minutes...

This is a fairly primitive toy I threw together today for a specific purpose, published in case it’s any use to others... feed it a list of words as command arguments, which it will then display as a 5x7 ASCII dotmatrix with ‘#’ as a dot & ‘_’ as a blank. /* * display text using a 5x7 bitmap font in ASCII letters */ static unsigned char font [] [5] = { { 0x00,0x00,0x00,0x00,0x00 }, // 0x20 32 { 0x00,0x00,0x6f,0x00,0x00 }, // ! 0x21 33 { 0x00,0x07,0x00,0x07,0x00 }, // " 0x22 34 { 0x14,0x7f,0x14,0x7f,0x14 }, // # 0x23 35 { 0x00,0x07,0x04,0x1e,0x00 }, // $ 0x24 36 { 0x23,0x13,0x08,0x64,0x62 }, // % 0x25 37 { 0x36,0x49,0x56,0x20,0x50 }, // & 0x26 38 { 0x00,0x00,0x07,0x00,0x00 }, // ' 0x27 39 { 0x00,0x1c,0x22,0x41,0x00 }, // ( 0x28 40 { 0x00,0x41,0x22,0x1c,0x00 }, // ) 0x29 41 { 0x14,0x08,0x3e,0x08,0x14 }, // * 0x2a 42 { 0x08,0x08,0x3e,0x08,0x08 }, ...

Citizens Augmenting Government Waste

So here we have Microsoft-funded “ Citizens Against Government Waste ” (CAGW) heavily criticising Massachusetts’s switch to an internationally accepted and open document standard (not open source, open standard — but I seem to remember a large monopolist who frequently confuses the two when it suits them). I remember CAGW, they were the organisation who had dead people writing in to support Microsoft in court a few years ago — thanks to sbergman27 for the link — is this “the dead hand of CAGW” at work again? Let’s follow the money and find out. Who stands to lose the most money and control if Massachusetts switches to an unencumbered document format? Big surprise, it’s CAGW sponsor Microsoft, through their dominant MS-Office suite. Why did CAGW list Microsoft’s suite last, after two other much-less-dominant examples which are waning anyway? If you’re inclined to wallow in additional irony, consider that at leas...