0

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.

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by msrikanth
0

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.

Edited by Mouche: n/a

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.