Posts Tagged ‘curl’

checkurl: Prüfen, ob ein Wort auf einer Webseite vorkommt

Mit dem folgenden Bash-Script kann man prüfen, ob auf einer Webseite ein bestimmtes Wort vorkommt:

#!/bin/bash

if [ $# -ne 2 ]; then
        echo "Usage: checkurl [URL] [string to search for]"
        echo
        echo "Exits with:"
        echo "    0=string found"
        echo "    1=string not found"
        exit 100
fi

cres=`curl -s $1 | grep -c $2`

if [ $cres -lt 1 ]; then
        echo "not found"
        exit 1
else
        echo "found"
        exit 0
fi

Voraussetzung: curl sollte installiert sein