File: check_for_x_errors.sh

package info (click to toggle)
linkchecker 4.9-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,308 kB
  • ctags: 3,736
  • sloc: python: 21,328; lex: 1,114; yacc: 781; ansic: 551; makefile: 244; sh: 100; sql: 19; awk: 4
file content (35 lines) | stat: -rwxr-xr-x 996 bytes parent folder | download
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
#!/bin/sh
# This script is in the public domain.
# Author of this script is Daniel Webb
# Modified by Bastian Kleineidam:
# - added hash-bang first line
# - documentation
# - removed second function, run them commands as-is
#
# Check web site links once per day, report only when the check had more
# than X errors.
#   Return 0
# arguments:
#   $1 - web site URL
#   $2 - notification email
#   $3 - threshold number of errors
#
function die() { echo "$0: $*"; exit 1; }

logfile=/tmp/linkchecker.log
[ -z "$1" -o -z "$2" -o -z "$3" ] && die "check_web_links requires three arguments"
do_check=false
if [ ! -f $logfile ]; then
    do_check=true
else
    # Has it been at least a day since last check?
    find $logfile -mtime +1 | grep link && do_check=true
fi
if [ $do_check = true ]; then
    linkchecker $1 >$logfile 2>/dev/null
    errors=$(grep Error: $logfile | wc -l)
    if [ $errors -gt $3 ]; then
        cat $logfile | mail -s "linkchecker: more than $3 errors" $2
    fi
fi
return 0