Monday, June 18, 2007

get last X hours ( 3 in this script )

CurrentHour=`date +%H`
CurrentMinute=`date +%M`
CurrentHour=`expr $CurrentHour - 3`
if [ $CurrentHour -lt 1 ]; then
hourFix=`expr 0 - $CurrentHour`
#echo $hourFix
CurrentHour=`expr 24 - $hourFix`
fi
case $CurrentHour in
[0-9]) CurrentHour=0$CurrentHour;;
esac
echo sekarang jam : `date +%H`:`date +%M`
echo 3 jam yg lalu : $CurrentHour:`date +%M`


and this one GET DATE on LINUX machine :

echo "how many days ?"
read x
now=`date +%s`
let "leap=now-(x*86400)"

echo "$x days ago was "`date -d "1970-01-01 $leap sec" +%Y%m%d`

0 Comment :