I searched the AskUbuntu database but the closest thing I found was a question on how to log errors.
What I'm looking for is to append to a log file / audit trail every time sudo gedit / gksu gedit / pkexec gedit is used. In reality I'll be using a wrapper script called
gsu that calls
What I would like to do is append to a audit file say
~/gedit-log the following:
YYYY-MM-DD hh:mm:ss Count /SystemDirectoryName/SystemFileName
Keep in mind I may navigate to /SystemDirectoryName and then call
gsu gedit SystemFileName so the the first parameter can't be automatically used because the path must be prepended. Therefore a bash command "here is the file name, give me the full path and file name" is required.
The current date and time should be in human readable format (not the number of seconds from 1970 (epoch time)). The Date and Time mask in the example is probably inappropriate and should conform to industry standards instead.
A command is needed to append the combination string + CR/LF (Carriage Return Line Feed) to the audit trail / log file.
Down the road a massaging program / script would be needed to tally up all the times a given file has been edited (/etc/default/grub could get a lot of edits) into the "count" field and delete the extraneous records. This would probably be a
cron daily job?
It might make sense to have two date/time fields. One for first time changed and one for last time changed.
Hopefully this code already exists in the Linuxverse or something close to it can be easily adapted.
The code itself might be put into a separate bash script so it can be re-purposed for many situations... ie this user edited that payroll file, etc.