[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to log bash commands (like with history or 'script' utility, bu
From: |
Dennis Williamson |
Subject: |
Re: how to log bash commands (like with history or 'script' utility, but better) |
Date: |
Tue, 29 Nov 2022 18:42:20 -0600 |
On Tue, Nov 29, 2022 at 5:37 PM Alexander Kolodziej <
alexander.kolodziej@gmail.com> wrote:
> 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??
>
One of my functions posted as Stack Overflow answers here:
https://stackoverflow.com/a/960684/26428
or others of mine at the same question could probably be adapted for your
needs.
--
Visit serverfault.com to get your system administration questions answered.
- how to log bash commands (like with history or 'script' utility, but better), Alexander Kolodziej, 2022/11/29
- Re: how to log bash commands (like with history or 'script' utility, but better),
Dennis Williamson <=
- Re: how to log bash commands (like with history or 'script' utility, but better), Greg Wooledge, 2022/11/29
- Re: how to log bash commands (like with history or 'script' utility, but better), address@hidden, 2022/11/30
- Re: how to log bash commands (like with history or 'script' utility, but better), address@hidden, 2022/11/30