[55] | 1 | #! /bin/sh |
---|
[75] | 2 | #+ |
---|
| 3 | # NAME |
---|
| 4 | # ==== |
---|
[2] | 5 | # |
---|
[75] | 6 | # linkchecker.sh - check links of a given directory or url |
---|
| 7 | # |
---|
| 8 | # SYNOPSYS |
---|
| 9 | # ======== |
---|
| 10 | # |
---|
| 11 | # :: |
---|
| 12 | # |
---|
| 13 | # $ linkchecker.sh -d dircheck -u url |
---|
| 14 | # |
---|
| 15 | # |
---|
| 16 | # DESCRIPTION |
---|
| 17 | # =========== |
---|
| 18 | # |
---|
[50] | 19 | # check links of a given directory or url |
---|
[2] | 20 | # cf. install.sh |
---|
| 21 | # |
---|
[75] | 22 | # |
---|
| 23 | # EXAMPLES |
---|
| 24 | # ======== |
---|
| 25 | # |
---|
| 26 | # |
---|
| 27 | # FILES |
---|
| 28 | # ===== |
---|
| 29 | # |
---|
| 30 | # original location |
---|
| 31 | # ~~~~~~~~~~~~~~~~~ |
---|
| 32 | # |
---|
[50] | 33 | # /usr/home/fplod/src/superbib_ws/linkchecker.sh sur aedon.locean-ipsl.upmc.fr |
---|
[2] | 34 | # |
---|
[75] | 35 | # EVOLUTIONS |
---|
| 36 | # ========== |
---|
| 37 | # |
---|
[26] | 38 | # ++ linkchecker ne voit pas les erreurs !! |
---|
[75] | 39 | # |
---|
[26] | 40 | # ++ dirpublish forme fplod@cerbere.locean-ipsl.upmc.fr:./WWW/ par example |
---|
| 41 | # donc pas http |
---|
[2] | 42 | # |
---|
[75] | 43 | # + ajouter la possibilite de faire une carte du site avec raphiz |
---|
| 44 | # |
---|
| 45 | # exemple syntaxe |
---|
| 46 | # |
---|
| 47 | # :: |
---|
| 48 | # |
---|
| 49 | # $ linkchecker -odot -v http://www.lodyc.jussieu.fr/NEMO/general/biblio_new/ | dot -Tps > sitemap.ps |
---|
| 50 | # |
---|
| 51 | # |
---|
[27] | 52 | # remove "set -u" because I don't know how to test if there is at least |
---|
| 53 | # one directory AND one url to be checked without this option |
---|
[75] | 54 | # |
---|
[27] | 55 | # !! ++ must be restore ASAP |
---|
[75] | 56 | # |
---|
[33] | 57 | # $Id$ |
---|
[26] | 58 | # |
---|
[75] | 59 | # - fplod 2008-09-16T15:28:34Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 60 | # |
---|
| 61 | # * comment in ReStructured Text |
---|
| 62 | # |
---|
| 63 | # - fplod 2007-10-12T07:32:08Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 64 | # |
---|
| 65 | # * add -u pour url |
---|
| 66 | # * add multiple -d and suppression of interactivity |
---|
| 67 | # * replace -w by -d (more generic) |
---|
| 68 | # * use rather checklink than linkchecker because the first one exist either |
---|
| 69 | # on Mac and Unix, and because the second one exists only on Mac and |
---|
| 70 | # does'nt seem to detect every problem |
---|
| 71 | # |
---|
| 72 | # - fplod 2007-10-11T15:31:25Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 73 | # |
---|
| 74 | # * parametrization |
---|
| 75 | # * merge with checklink.sh ++ choisir entre les deux |
---|
| 76 | # |
---|
| 77 | # - fplod 2007-06-19T09:26:04Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 78 | # |
---|
| 79 | # * création |
---|
| 80 | #- |
---|
| 81 | system=$(uname) |
---|
| 82 | case "${system}" in |
---|
| 83 | AIX|IRIX64) |
---|
| 84 | echo " www : no specific posix checking" |
---|
| 85 | ;; |
---|
| 86 | *) |
---|
| 87 | set -o posix |
---|
| 88 | ;; |
---|
| 89 | esac |
---|
[26] | 90 | command=$(basename ${0} .sh) |
---|
| 91 | log_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") |
---|
| 92 | log=/tmp/${command}.log.${log_date} |
---|
[2] | 93 | # |
---|
[26] | 94 | usage=" Usage : ${command} -d dircheck -u url" |
---|
[2] | 95 | # |
---|
[26] | 96 | minargcount=2 |
---|
| 97 | #echo " narg ${#}" |
---|
| 98 | if [ ${#} -lt ${minargcount} ] |
---|
[2] | 99 | then |
---|
[26] | 100 | echo "eee : not enought arguments" |
---|
| 101 | echo "${usage}" |
---|
| 102 | exit 1 |
---|
[2] | 103 | fi |
---|
| 104 | # |
---|
[26] | 105 | idircheck=0 |
---|
| 106 | iurl=0 |
---|
| 107 | while [ ! -z "${1}" ] |
---|
| 108 | do |
---|
| 109 | case ${1} in |
---|
| 110 | -d) |
---|
| 111 | idircheck=$(( ${idircheck} + 1 )) |
---|
| 112 | dircheck[${idircheck}]=${2} |
---|
| 113 | shift |
---|
[2] | 114 | ;; |
---|
[26] | 115 | -u) |
---|
| 116 | iurlcheck=$(( ${iurlcheck} + 1 )) |
---|
| 117 | urlcheck[${iurlcheck}]=${2} |
---|
| 118 | shift |
---|
[2] | 119 | ;; |
---|
[26] | 120 | esac |
---|
| 121 | shift # next flag |
---|
| 122 | done |
---|
[2] | 123 | # |
---|
[55] | 124 | # +++ remove temporarily |
---|
[27] | 125 | # +++ set -u |
---|
[2] | 126 | # |
---|
[26] | 127 | # ++ check directories or URL |
---|
| 128 | # |
---|
| 129 | # choose the command to be used |
---|
| 130 | # |
---|
| 131 | commandcheck=checklink |
---|
| 132 | # |
---|
| 133 | if [ ${commandcheck} = "linkchecker" ] |
---|
| 134 | then |
---|
| 135 | # test if linkchecker is available |
---|
| 136 | type ${commandcheck} 1> /dev/null 2>&1 |
---|
| 137 | status=${?} |
---|
| 138 | if [ ${status} -ne 0 ] |
---|
| 139 | then |
---|
| 140 | echo "${command} : eee : ${commandcheck} unavailable" |
---|
| 141 | exit 1 |
---|
| 142 | fi |
---|
| 143 | optcheck="--anchors --recursion-level=-1" |
---|
| 144 | fi |
---|
| 145 | # |
---|
| 146 | if [ ${commandcheck} = "checklink" ] |
---|
| 147 | then |
---|
| 148 | # test if checklink is available |
---|
| 149 | type ${commandcheck} 1> /dev/null 2>&1 |
---|
| 150 | status=${?} |
---|
| 151 | if [ ${status} -ne 0 ] |
---|
| 152 | then |
---|
| 153 | echo "${command} : eee : ${commandcheck} unavailable" |
---|
| 154 | exit 1 |
---|
| 155 | fi |
---|
| 156 | # |
---|
| 157 | optcheck="--summary --recursive" |
---|
| 158 | fi |
---|
| 159 | # |
---|
| 160 | # loop on directories to be checked |
---|
[27] | 161 | dirchecksize=${#dircheck[@]} # ++ pb set -u |
---|
| 162 | if [ ${dirchecksize} -gt 0 ] |
---|
| 163 | then |
---|
| 164 | idircheck=1 |
---|
| 165 | while [ ${idircheck} -le ${dirchecksize} ] |
---|
| 166 | do |
---|
| 167 | echo "iii : beginning of check of ${dircheck[${idircheck}]}" 1>>${log} |
---|
| 168 | fverif="file://"${dircheck[${idircheck}]} |
---|
| 169 | echo "iii : check of ${fverif}" |
---|
| 170 | ${commandcheck} ${optcheck} ${fverif} 1>>${log} 2>&1 |
---|
| 171 | idircheck=$(( ${idircheck} + 1 )) |
---|
| 172 | done |
---|
| 173 | fi |
---|
[26] | 174 | # |
---|
[27] | 175 | # loop on urls to be checked |
---|
| 176 | urlchecksize=${#urlcheck[@]} # ++ pb set -u |
---|
| 177 | if [ ${urlchecksize} -gt 0 ] |
---|
| 178 | then |
---|
| 179 | iurlcheck=1 |
---|
| 180 | while [ ${iurlcheck} -le ${urlchecksize} ] |
---|
| 181 | do |
---|
| 182 | echo "iii : beginning of check of ${urlcheck[${iurlcheck}]}" 1>>${log} |
---|
| 183 | # ++ test si urlcheck commence par http ou pas |
---|
| 184 | fverif=${urlcheck[${iurlcheck}]} |
---|
| 185 | echo "iii : check of ${fverif}" |
---|
| 186 | ${commandcheck} ${optcheck} ${fverif} 1>>${log} 2>&1 |
---|
| 187 | iurlcheck=$(( ${iurlcheck} + 1 )) |
---|
| 188 | done |
---|
| 189 | fi |
---|
[26] | 190 | # |
---|
| 191 | echo "iii : log in ${log}" |
---|
| 192 | # end |
---|
[2] | 193 | exit |
---|