I am trying to code a script to log all commands executed on a server, currently I have 2 versions:
(simplified version of the scripts)
Version 1:
function fc
{
fc -ln -0
}
trap fc DEBUG
Version 2:
function fc
{
cmd=`fc -ln -0`
echo $cmd
}
trap fc DEBUG
The script is inluded in /etc/bash.bashrc : source script.sh
The problem is that when I run this scripts I don't get the same result:
When I run the first verion I get the command that triggered the trap :
SERVER#
SERVER#
SERVER# test
SERVER# ls
ls
But when I run the second I get the last-1 command :
SERVER#
SERVER#
SERVER# test
SERVER# ls
test
Thanks in advance.
fc
in a different process, so you won't have the same history.fc -ln -0; echo $cmd and cmd=
fc -ln -0`, I had the same result.