Skip to content

Instantly share code, notes, and snippets.

@petrjoachim
Last active August 29, 2015 13:57
Show Gist options
  • Save petrjoachim/9363093 to your computer and use it in GitHub Desktop.
Save petrjoachim/9363093 to your computer and use it in GitHub Desktop.
Skript s bezpečně předaným heslem do wgetu pro dávkové použití.
#!/bin/bash -e
USER=$1
shift
read -s -p "Password for username $USER: " PASSWORD; echo
for FILE in "$@"
do
OUTPUT=`echo $FILE | sed "s/https*:\/\/\([^.]*\.[^.]*\).*\/\(.*\)/\1-\2/g"`
# v aktualnim adresari vytvorime namedpipe
mkfifo trubka.$$
# wgetneme soubor a pockame si na predani hesla pres trubku
wget -O "$OUTPUT" --no-check-certificate --user "$USER" --config trubka.$$ $FILE &
PID=$!
# zapiseme do trubky heslo a trubku pak hned smazeme
echo -e "password=$PASSWORD\n" > trubka.$$
rm -f trubka.$$
# pockame az proces skonci a jede se dal
wait $PID
done
#!/bin/bash -e
USER=$1
shift
read -s -p "Password for username $USER: " PASSWORD; echo
while true;
do
for FILE in "$@"
do
OUTPUT=`echo $FILE | sed "s/https*:\/\/\([^.]*\.[^.]*\).*\/\(.*\)/\1-\2/g"`
# v aktualnim adresari vytvorime namedpipe
mkfifo trubka.$$
# wgetneme soubor a pockame si na predani hesla pres trubku
# wget -c pokracuje ve stahovani (hodi se na tail vzdaleneho souboru)
wget -c -O "$OUTPUT" --no-check-certificate --user "$USER" --config trubka.$$ $FILE &
PID=$!
# zapiseme do trubky heslo a trubku pak hned smazeme
echo -e "password=$PASSWORD\n" > trubka.$$
rm -f trubka.$$
# pockame az proces skonci a jede se dal
wait $PID
sleep 1
done
done
@rembish
Copy link

rembish commented Mar 20, 2014

Squeeze version (wget in squeeze doesn't support --config option):

#!/bin/bash -e

USER=$1
shift

read -s -p "Password for username $USER: " PASSWORD; echo

for FILE in "$@"
do
    OUTPUT=`echo $FILE | sed "s/https*:\/\/\([^.]*\.[^.]*\).*\/\(.*\)/\1-\2/g"`

    # v aktualnim adresari vytvorime namedpipe
    mkfifo trubka.$$

    # curlneme soubor a pockame si na predani hesla pres trubku
    curl -o "$OUTPUT" --insecure -# --config trubka.$$ $FILE &
    PID=$!

    echo -e "user = \"$USER:$PASSWORD\"\n" > trubka.$$
    rm -f trubka.$$

    # pockame az proces skonci a jede se dal
    wait $PID
done

@petrjoachim
Copy link
Author

Ještě verze od Luboše Starého.

#!/bin/bash -e

USER=$1
shift

read -s -p "Password for username $USER: " PASSWORD; echo

# finta: wget si ho nacte sam bez nutnosti podpory --config optiony
export WGETRC="trubka.$$"

# pri breaku zrusim trubku
trap "rm -f $WGETRC" 1 2 3 15

for FILE in "$@"
do
    OUTPUT=`echo $FILE | sed "s/https*:\/\/\([^.]*\.[^.]*\).*\/\(.*\)/\1-\2/g"`

    # v aktualnim adresari vytvorime namedpipe
    mkfifo $WGETRC


    # zapiseme do trubky heslo, spusteno na pozadi
    echo -e "password=$PASSWORD\n" > $WGETRC &

    # wgetneme soubor a heslo vyctem z trubky
    wget -O "$OUTPUT" --no-check-certificate --user="$USER" $FILE

    # odmaznu ho pomaleji, ale to nevadi
    rm -f $WGETRC

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment