Wednesday, December 20, 2017

12.04 - Logging every time a command is run


I want to log every time I run a certain type of command in the terminal. For example, every time I run:


sudo apt-get install [something]

I want to add [something] to a log file in my home directory that will look like the following:


[timestamp] [something]
2012-10-02 mysql-server
2012-10-03 ruby1.9.1
2012-10-06 gedit-plugins
2012-10-07 gnome-panel synaptic

What's the easiest way to make this happen automatically?



The most straightforward way to do this would be to replace apt-get with a wrapper script which would log the data into a logfile and then invoke apt-get passing it all the parameters the wrapping script received (and returning the return code the original program returned).


If you're careful to mimic the behaviour of the original command very closely, nobody would notice any difference.


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...