Answer the question
In order to leave comments, you need to log in
How to deal with the date?
There is a site that once every 3-5 days gives a list of proxies to this URL: http://site.com/proxy/list_{dd.mm.YYYY}.txt
I need to do this:
Send a request to the url with today's date
If the status is 404, then reduce the date by 1 and send the request again and so on until I get the status 200
Bye there is this code:
get_proxy_list() {
savefile=~/.PROXY_LIST
date=$(date +%d.%m.%Y)
url="http://site.com/proxy/list_${date}.txt"
# Вот тут надо вкорячить while status -ne 200
status=$(wget --spider -S ${url} 2>&1 | grep "HTTP/" | awk '{print $2}')
if [ "${status}" -eq 200 ]; then
wget --output-document=${savefile} ${url} 2>&1
cat ${savefile}
elif [ -f ${savefile} ]; then
cat ${savefile}
else
echo "Proxy list not found"
fi
}
Answer the question
In order to leave comments, you need to log in
It all ended up like this:
__get_date() {
local date=$(date --date="-$1 day" +%d.%m.%Y)
echo ${date}
}
__get_url() {
local date="$1"
echo "http://webanetlabs.net/freeproxylist/proxylist_at_${date}.txt"
}
__get_status() {
local offset="$1"
local date=$(__get_date ${offset})
local __url=$(__get_url ${date})
local status=$(wget --spider -S ${__url} 2>&1 | grep "HTTP/" | awk '{print $2}')
echo "${status}"
}
get_proxy_list() {
local savefile=~/.PROXY_LIST
local counter=0
while [ $(__get_status ${counter}) != "200" ]; do
counter=$(($counter + 1))
done
local date=$(__get_date ${counter})
local url=$(__get_url ${date})
wget --output-document=${savefile} ${url} > /dev/null 2>&1
cat ${savefile}
}
Remake it first
get_proxy_list() {
savefile=~/.PROXY_LIST
date=$(date +%d.%m.%Y)
url="http://site.com/proxy/list_${date}.txt"
...
}
make_dmy_date() {
date "+%d.%m.%Y"
}
make_proxy_url() {
echo "http://site.com/proxy/list_$(make_dmy_date).txt"
}
make_proxy_ofname() {
echo "~/.PROXY_LIST"
}
get_proxy_list() {
url=$1
savefile=$2
...
}
get_proxy_list `make_proxy_url` `make_proxy_ofname`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question