Glen Turner (vk5tu) wrote,

Timestamps for commands

When tracking bugs it is useful to have the time the command was run. This is particularly so with networking bugs, as traffic counters without the time they were observed are a bit pointless. It's handy if each command is automatically timestamped.

Cisco IOS
Router> terminal exec prompt timestamp 
Router> show version
Load for five secs: 5%/5%; one minute: 5%; five minutes: 5%
Time source is NTP, 07:01:02.345 UTC Fri Aug 2 2013
Cisco IOS Software...

You can make this the login default:

line vty 0 15
 exec prompt timestamp
Juniper JUNOS
root@amnesiac> set cli timestamp format "%Y-%m-%d %T"
root@amnesiac> show version 
2013-08-02 07:01:02
Hostname: amnesiac...
There is a command macro facility you can use to make this the login default.
Linux
$ trap 'date --utc "+%Y-%m-%d %H:%M:%S.%N"' DEBUG
$ uname -r
2013-08-02 07:01:02.157011493
3.9.6-200.fc18.x86_64
2013-08-02 07:01:02.159011493

If you just want to print the command start time then there is discussion of pre-exec hooks for bash here and a well-known script.

You can make this the login default by editing ~/.bash_profile in the usual way.

  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments