This is a general problem that how you will check moodle login with a script. I have written a custom script which I want to share with you that helps us check the login in moodle and escalate it via Nagios in case it fails. Now the question arises why I want to check moodle login. The answer is as simple as to make sure all the service moodle require to function properly are working fine like (mysql, ldap, webserver). Please find the script below to check the moodle login

#!/bin/sh
#usage sh script server userid password
# sh x moodle.example.com user password
chklogin=”
URL=$1
username=$2
password=$3
cookies=$4
rm -f /tmp/${4}*.txt
curl -b /tmp/$i{4}.txt -c /tmp/$4.txt http://${1}/moodle/login/index.php &>/dev/null
curl -b /tmp/$4.txt -c /tmp/$4.txt -d “username=$2&password=$3” http://$1/moodle/login/index.php &>/dev/null
chklogin=`curl -b /tmp/${4}.txt -c /tmp/${4}.txt -d “username=${2}&password=${3}” http://${1}/moodle/index.php 2>/dev/null | grep “You are logged in as”`
p=`echo $chklogin | awk -F “>” ‘{ print $3 }’ | awk -F “<” ‘{ print $1 }’ | head -1` if [ -z “$p” ]; then echo login failed STATE_CRITICAL=2 exit $STATE_CRITICAL elif [ “$p” = “You are logged in as ” ]; then echo login OK echo $p STATE_OK=0 exit $STATE_OK fi The assumption here is that moodle resides under /var/www/html/moodle/ and the last highlighted section is for nagios alerts. Please feel free to contact for more information and do give us your feedback.