LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   tcsh: Log all commands to syslog (https://www.linuxquestions.org/questions/linux-software-2/tcsh-log-all-commands-to-syslog-4175429881/)

pingu 10-01-2012 09:06 AM

tcsh: Log all commands to syslog
 
On a server requirements are that all commands issued by root or using sudo must be sent to syslog, with real user's name (PCI requirement).
For the standard shell (bash) this is not a problem, simply added this line to /root/.bashrc:
Code:

PROMPT_COMMAND='history -a >(tee -a ~/.bash_history | logger -t "$USER[$$] $SUDO_USER[$$] $SSH_CONNECTION")'
But the server also has tcsh, how do I configure it there?
I've tried to use 'precmd' in /root/.cshrc but it fails to log anything. The closest I got is
Code:

alias precmd tee -a ~/.history | logger -t "$USER[$$] $SUDO_USER[$$]"
This doesn't output any error message when switching shell to tcsh, but still nothing is logged.
Putting single quote around the command almost works - when logging in it's like command waiting to finish, if I press <enter> I get a line in /var/log/messages - so it obviously logs to syslog! (And I've tried all 3 single quotes).
But then, the prompt just hangs, like with a not completed command.
Setting the command between parenteses I get "Badly placed ()'s"

And tcsh cannot be removed (required by subversion and some other apps we simply must have).
Server is running OpenSuse 12.1.

Any ideas?

unSpawn 10-01-2012 10:33 AM

Quote:

Originally Posted by pingu (Post 4793998)
On a server requirements are that all commands issued by root or using sudo must be sent to syslog, with real user's name (PCI requirement).
For the standard shell (bash) this is not a problem, simply added this line to /root/.bashrc:
Code:

PROMPT_COMMAND='history -a >(tee -a ~/.bash_history | logger -t "$USER[$$] $SUDO_USER[$$] $SSH_CONNECTION")'

While that's certainly creative (and let's forego talking about protecting variables) it relies on the user land process itself to perform logging and I hope you can see what uncertainties (at least) that causes wrt the integrity of what's being logged (and how will you find out if nothing was logged BTW? ;-p).


Quote:

Originally Posted by pingu (Post 4793998)
Any ideas?

We've actually got quite a few "I want to log everything"-like threads at LQ. If you search for my handle in combination with search terms like audit, rootsh, sudosh you should find some to read.


All times are GMT -5. The time now is 01:50 PM.