mkloader.sh

coderodde 15.05.12 14:24

Bash - skripti mureakuha - pätkien lokaalia varmuuskopiointia varten.

 Tekstiversio  Arvo: 0 (0 ääntä)  Äänestä: +  -
#!/bin/bash

#######################################################
# Given the mureakuha user IDs xxxx, yyy, zzzz, the   #
# ivocation of this script (./mkloader xxxx yyy zzzz) #
# will download their code snippets, if available.    #
#######################################################

# Prints the usage info.
function printUsage {
    echo "Usage: $(basename $0) USER_ID1 USER_ID2 ..."
}
 
# Downloads all the code snippets of a given mureakuha user ID,
# and stores them in the text files (residing in the current
# directory) named after their respective code snippet IDs.
function loadSnippetsByUser {
    for cid in $(curl http://mureakuha.com/kayttajat/$1 |
                 grep -o '\/koodikirjasto\/[0-9]\+' |
                 grep -o '[0-9]\+'
                ); do
        curl http://mureakuha.com/dl.php?type=1\&id=$cid > $cid.txt    
    done
}

# Check the command line.
if [[ $# -lt "1" ]]; then
    printUsage
    exit 1
fi

# For each given user ID, download all the snippets.
for uid in $@; do
    loadSnippetsByUser $uid
done

coderodde 14:30 15.5.12 
Seuraavilla bash - tulkin versioilla on toiminut hyvin:
(1) 4.1.5(1)-release
(2) 3.2.48(1)-release

Käyttö seuraavanlaista: mikäli kahden mielenkiintoisen mureakuhan käyttäjän ID:t ovat esim. 10122 ja 20244, niin komento
./mkloader 10122 20244
lataa heidän koodipätkät. Ladatut pätkät päättyvät txt - tiedostoiksi (nykyisessä työkansiossa), joiden nimenä ovat edellisten ID:t (esimerkiksi 1234.txt).