Last active
August 29, 2015 13:57
-
-
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í.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
Squeeze version (wget in squeeze doesn't support --config option):