help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how to log bash commands (like with history or 'script' utility, but bet


From: Alexander Kolodziej
Subject: how to log bash commands (like with history or 'script' utility, but better)
Date: Wed, 30 Nov 2022 00:18:08 +0100

Hi!

I would like to log all (interactive) commands that are entered at the
prompt during an ssh/console session. Like this

* the command (and its arguments)
* time/date
* who executed (just $USER will not suffice, because accounts are shared in
this case, and people are differentiated by their ssh key fingerprints,
which can be found as variables in the environment)
* and would be nice to have $PWD logged as well (where that command was
executed)

The bash history (with HISTTIMEFORMAT) takes care of the first two, but not
the latter two.

I was hoping that i could do something with $PS0 and $BASH_COMMAND, but it
looked like BASH_COMMAND was set to the previous command (it lagged behind
so to speak) when PS0 is evaluated.

I would really like to avoid to download stuff from github and compile. I
want something that gets updated with the rest of the packages when 'apt
upgrade' is run.

The 'script' utility? Well maybe.But it looks like that will try to log
everything entered in e.g. 'vi' as well, and from what i read - ot
handle that very good.
Also, doesnt look like i can log specific/custom env variables with that.

It just really seems that there should be some simple way to do this within
bash itself.
Isnt there? :)

  wbr / Alex

ps. Perhaps some readline magic somehow??


reply via email to

[Prev in Thread] Current Thread [Next in Thread]