With the bash shell, you can install a trap on the synthetic DEBUG
signal. This is useful and will execute your function or bit of code on every shell command. For example:
$ trap 'logger -t shell "${BASH_COMMAND}"' DEBUG
The idea here is to install the trap in a file dropped in, for instance, /etc/profile.d/bash-logger
and have any user shell session commands logged automatically to syslog whenever they happen. This is also useful to easily trace remote commands.
Looking at the dash shell source code, I seem to understand there's no such DEBUG
signal available.
Are there any workarounds or alternatives to achieve the same result with the dash shell?
while read -r line; do logger -t shell "$line"; command "$line"; done < myscript.sh
? If it works I may add some line more in an answer.eval "$line"
eval <command>
and I cancel the wrong part, it happens... of course always if you do not want to force your script to use commands on disk instead of the alias/function ones...◉‿◉
/etc/profile.d/bash-logger
and have any user shell session commands logged automatically to syslog.