Hi Everyone,
I have written a C Shell wrapper script for "cat" command in the linux such that whenever any uses the "cat" command and it logs to some file, so the script is as

#!/bin/tcsh -f

set command = /etc/temp/cat
set logfile = /etc/cat_command.log

echo "$LOGNAME + $command $argv " >> $logile
$command $argv

So , i have move the original "cat" command from "/bin" and replaced it with this script so whenever any one uses it logs

But my problem is whenver any user uses as
1) cat sample.txt or cat 1.txt 2.txt , it will log properly
2) cat sample.txt > /tmp/temp.txt , for this only command and arguments are logged but redirection and redirection path is not logged so is there any way to log that path also.

Looking forward your reply as it is urgent. Thanks in Advance

Thanks
Srikanth M.

Member Avatar for Mouche

Your program cannot tell whether or not there is redirection. It will only get the $argv.

If you want to see everything, you could log the shell output. If you're using tsch, you can configure some history settings in your ~/.tschrc to have continuous logging to ~/.tschrc_history:

set history = 1000
set savehist = (1000 merge)
set histfile = ~/.tcsh_history

Then you could filter that file using "grep cat ~/.tschrc_history" or something similar.

Your program cannot tell whether or not there is redirection. It will only get the $argv.

If you want to see everything, you could log the shell output. If you're using tsch, you can configure some history settings in your ~/.tschrc to have continuous logging to ~/.tschrc_history:

set history = 1000
set savehist = (1000 merge)
set histfile = ~/.tcsh_history

Then you could filter that file using "grep cat ~/.tschrc_history" or something similar.

Hi LaMouche,
Yes we can log shell output but the user can remove that "~/.tcshrc_history" as he had full permission for that file. So that's why i have created a my own "cat" command which log the output to the specified location.

Thanks
Srikanth M.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.