History with timestamps

Stumbled accross this neat future some days ago.

Normally, history alias calls “fc -c” without any indication when a command has been executed. If you call “fc -t” it does give you the timestamp of the commands:

562     2012/08/02 14:29:07 :: ssh dehq0srd history
563     2012/08/02 14:31:29 :: history
564     2012/08/02 14:31:33 :: dsh history
565     2012/08/02 14:33:56 :: history

To achive this, you need to put following into /etc/environment & profiles:

/etc/profile

alias history=’fc -t’

/etc/environment

EXTENDED_HISTORY=ON

HIST_ID=$(who am i | awk ‘{print $1}’)

HIST_TTY=$(tty | awk -F / ‘{print $NF}’)

export HISTFILE=/var/hist/${HIST_ID}_${HIST_TTY}_$(date +”%d.%m.%y”)

touch $HISTFILE 2>/dev/null

chmod 666 $HISTFILE 2>/dev/null

export HISTSIZE=50000

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s