Пожалуйста, помогите проверить, почему следующий скрипт не работает.Сценарий Bash для загрузки изображений
#!/bin/bash -x
#Description: Images downloader
#Filename: img_downloader.sh
if [ $# -ne 3 ];
then
echo "Usage: $0 URL -d DIRECTORY"
exit -1
fi
for i in {1..4}
do
case $1 in
-d) shift; directory=$1; shift ;;
*) url=${url:-$1}; shift;;
esac
done
mkdir -p $directory;
baseurl=$(echo $url | egrep -o "https?://[a-z.]+")
curl –s $url | egrep -o "<img src=[^>]*>" | sed 's/<img src=\"\([^"]*\).*/\1/g' > /tmp/$$.list
sed -i "s|^/|$baseurl/|" /tmp/$$.list
cd $directory;
while read filename;
do
curl –s -O "$filename" --silent
done < /tmp/$$.list
В результате это дает выглядит следующим образом:
bash-3.2$ ./img_downloader.sh https://www.web-statistics.org -d images
./img_downloader.sh: line 1: bash-3.2$: command not found
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: –s
0 0 0 0 0 0 0 0 --:--:-- 0:00:04 --:--:-- 0curl: (60) SSL certificate problem: Invalid certificate chain
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
sed: 1: "/tmp/1638.list": invalid command code 1
попробуйте использовать опцию '-k' для завивки или установить ssl-сертификат веб-статистики в ваш каталог ssl cert. –
Редактирование удалено 'bash-3.2 $' из первой строки скрипта, но сообщение об ошибке выглядит так, будто оно было на самом деле в первой строке файла, хотя, очевидно, этого не должно быть. Не могли бы вы проследить за подтверждением и/или обновить вопрос, чтобы правильно отразить, что произойдет, если вы удалите любую такую строку? – tripleee
Предупреждения, которые вы получаете от http://www.shellcheck.net/, также могут быть уместными. Вы действительно должны правильно указывать свои переменные. – tripleee