-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathurl_process_https.sh
More file actions
executable file
·46 lines (31 loc) · 1.47 KB
/
url_process_https.sh
File metadata and controls
executable file
·46 lines (31 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
#Petit script pour voir s'il existe une url en https au lieu de http !
#si oui, propose alors d'utiliser alors l'url https
#ATTENTION: ça été fait pour une structure perso !
#faudra modifier le script pour d'autres structures
#zf190229.1733
#source: https://stackoverflow.com/questions/428109/extract-substring-in-bash
#note:
#test si l'argument est vide
if [ -z "$1" ]
then
echo -e "
Syntax:
./url_process_https.sh http://www.epfl.ch
"
exit
fi
shopt -s extglob #demande au bash de supporter les pipe !
r=$1
r=`echo $r | sed "s/\http/https/g"` #converti une url http en url https
r=`echo $r | sed "s/\httpss/https/g"` #converti une url httpss en url https, bug de si l'url était déjà en https :-)
curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36" --insecure --max-time 5 $r 2>err.txt > html.txt #récupère le contenu HTML de la page web
#traitement des erreurs de connection au niveau du CURL
e=`cat err.txt |grep -i -e 'Failed to connect' -e 'Connection timed out after' -e 'Could not resolve host' `
e="${e:1}" #enlève le 1er caractère !
if [ "$e" != "" ]
then
# echo -e "err: "$1", "$e >> err.log
r=`echo $r | sed "s/\https/http/g"` #converti une url https en url http
fi
echo $r