Check moodle web login script

October 7, 2016

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

#usage sh script server userid password
# sh x user password
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 [fusion_builder_container hundred_percent=”yes” overflow=”visible”][fusion_builder_row][fusion_builder_column type=”1_1″ background_position=”left top” background_color=”” border_size=”” border_color=”” border_style=”solid” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”no” center_content=”no” min_height=”none”][ -z “$p” ];
then echo login failed
elif [ “$p” = “You are logged in as ” ];
echo login OK
echo $p
exit $STATE_OK
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.

Contact Us
We are simple a phone call and email away from you.
GET IN TOUCHConnect with us
Contact Us
We are simple a phone call and email away from you.

Copyright by Xeois. All rights reserved.

Copyright by Xeois. All rights reserved.