Showing posts with label reverse. Show all posts
Showing posts with label reverse. Show all posts

Sunday, August 25, 2013

Call and store response from a url using bash script

#!/bin/bash

## generate random string of length 18

function randpass
{
        echo `</dev/urandom tr -dc A-Za-z0-9 | head -c18`
}


## get current time stamp

timestamp=$(date  +%s);
sessionId="$(randpass).$(randpass).$timestamp";
privateKey='test';
 

## get substring of sessionId from 0 to 5 characters.
sessionIdPart=${sessionId:0:5};
systemKeyPart=${privateKey:0:4};


## reverse string and store in a variable

word="$(echo "$sessionIdPart" | rev)$(echo "$systemKeyPart" | rev)";
word="$word$sessionId$privateKey";
 

## make a string md5
hash=`echo -n "$word" | md5sum | awk '{print $1}'`;
hash=${hash:0:10};
breakRest="securedSessionKey=$sessionId&securedHash=$hash";
 

saveFile=$(date +"%Y-%m-%d %T")
## saveFile would be '2013-08-25 19:23:28'

## calling a url using 'curl' and store response to some file.
curl -s -L -o "$saveFile.html" "http://domain.com/getStudent?$breakRest" &
## "&" sign at the end means run curl in background.

exit 1;