web analytics

Login to website using curl

Suppose there is a domain  divya.com which has a login form. You need to login to the site every hour, to make sure that the login is working. For that the following script helps, which can be run as a cron.


#!/bin/sh
cd /root/test/abc/
> cjar
> test2.txt
> test3.txt
##Cookies will be stored in the file cjar##
curl –cookie-jar cjar –data “username=abc@gmail.com&password=12345” –location “http://abc.com/login/” > test2.txt

##Specify the cookie file and access another link to see if it works. If login works, you will get the code of this page, otherwise it will get redirected to the login page itself, returning a 302 status code##


curl -b cjar http://abc.com/save_org > test3.txt

CODE=$(grep -o “302 – Found” test3.txt)
if [ “$CODE” == “302 – Found” ]
then
echo “abc.com Login not working, please check immediately” | mail -s “Urgent Login issue”  abc@gmail.com
fi


Execute the script for testing by giving the correct login details as well as wrong login details. If wrong details are given, check if you are getting mail to your address.

Now run the same as a cron every hour.


0       *      *        *       *       /bin/sh /root/test/abc/abc.sh

One comment to Login to website using curl

  • MlleAnemone  says:

    many thanks.. it’s exactly what i’ve been looking for:)

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>