Showing posts with label timestamp. Show all posts
Showing posts with label timestamp. 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;

Thursday, April 18, 2013

Get Unix timestamp in Java, Python, Erlang, JavaScript, Php

To Get Unix timestamp value in seconds
Java:
long timestamp = System.currentTimeMillis()/1000
Python:

import time
timestamp = int(time.time())
Erlang:

{Mega, Secs, _} = now(),
Timestamp = Mega*1000000 + Secs,
JavaScript:

var ts = Math.floor(Date.now()/1000);
// You can also use new Date().getTime()/1000 but this one is faster
Php:
$stamp = time();