#! /bin/bash
USER=$1
IP=$2
historyfile=/var/log/history/$USER-$IP-history
if [ $# != 2 ];then
    echo "=========================================="
    echo "User    IP"
    for fn in `ls /var/log/history/`;do
    	echo $fn | awk -F"-" '{print $1 "    "  $2}'
    done
    echo "=========================================="
    echo "Usage:  read-history User IP"
    exit 1
fi

if [ ! -f $historyfile ];then
    echo "Input Error: make sure have inputed the right username and IP!"
    exit 1
fi

while read line
do
  echo $line | grep "^#[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$" &> /dev/null
  if [ "$?" = "0" ];then
    historytime=`date -d "1970-01-01 UTC ${line:1} seconds" "+%F %H:%M:%S"`
    echo -en "$historytime "
  else
    echo -e  $line
  fi
done < $historyfile
