#!/bin/bash ### # Bash script based on basic linux command line tools to log in to OLAT start a course # from the home and logout again. On failure it sends an sms to a mobile phone specified. # Designed for usage in the network of university of Zurich. Addapt for you needs. # # That the script can start a course you have to create a user on the machine and put # on the olat desktop only one bookmark with the course you like to start and remove all # other portlets. If you do NOT have shibboleth as default auth provider you have to modifie # also the second step which grabs the normal login form # # initial date: 4. Sept. 2007 # author: Guido Schnider ### domain="olat.unizh.ch" port=":80" username="performance-test-user" password="*****" cutTime="10" #domain="localhost" #port=":8080" #username="administrator" #password="olat" #cutTime="10" HANDY=******* start=`date +%s` #grab loginpage and extract form action uri wget -o temp-log0 -O temp-startpage.html --save-cookies cookies.txt --keep-session-cookies http://$domain$port/olat/dmz/ sleep 1 # THIS step is optional - ONLY needed to get the normal (username/pw) loginform to front when shibboleth login is active #open normal login form page not shibboleth loginuri=`grep '?lp=OLAT' temp-startpage.html | sed 's/^.*href="//' | sed 's/".*$//'` #echo $loginuri wget -o temp-log1 -O temp-logform.html --save-cookies cookies.txt --keep-session-cookies --load-cookies cookies.txt http://$domain$port$loginuri sleep 1 #must be 1 otherwise the server is not available checkResponse=`grep 'name=\"loginForm\"' temp-logform.html | wc -l` if [ $checkResponse == 1 ] then uri=`grep 'name=\"loginForm\"' temp-logform.html | sed 's/^.*action="//' | sed 's/".*$//'` #echo $uri #login with extracted uri and post method wget -o temp-log2 -O temp-home.html --save-cookies cookies.txt --keep-session-cookies --load-cookies cookies.txt --post-data="lf_login=$username&lf_pass=$password&olat_fosm_0=Login" http://$domain$port$uri #sleep to let the instant messenger connect sleep 3 #start demo course from the homepage with direkt link, this only works if there a no other "cmd.launch" stuff is on the screen # best is to remove all other portlets except the bookmarks portlet courseuri=`grep 'cmd.launch\/' temp-home.html | sed 's/^.*href="//' | sed 's/".*$//'` #echo $courseuri #start course wget -o temp-log3 -O temp-course.html --save-cookies cookies.txt --keep-session-cookies --load-cookies cookies.txt http://$domain$port$courseuri #sleep to let the instant messenger create a chatroom sleep 3 #extract logout uri for later usage logouturi=`grep 'logout\/' temp-course.html | sed 's/^.*href="//' | sed 's/".*$//'` #echo $logouturi #logout wget -o temp-log4 -O temp-logout.html --save-cookies cookies.txt --keep-session-cookies --load-cookies cookies.txt http://$domain$port$logouturi sleep 1 #send sms if time is too long rm temp-* rm cookies.txt stop=`date +%s` #substract the sleep times echo `date`" time: "$(($stop-$start-9)) PROCESSTIME=$(($stop-$start-9)) if [ $PROCESSTIME -gt $cutTime ] then # only send sms after 3 o'clock in the morning (after restart phase) if [ `date +%H` -gt 3 ] then echo `date`"OLAT is slow! Login->start course->logout took ($PROCESSTIME)s" | /usr/bin/mail -s "OLAT performance alert!" -r "id_olat@olat.unizh.ch" $HANDY@sms.switch.ch fi fi else if [ `date +%H` -gt 3 ] then echo `date`" error - olat server not available by auto loginscript!" | /usr/bin/mail -s "OLAT performance alert!" -r "id_olat@olat.unizh.ch" $HANDY@sms.switch.ch fi fi