954,228 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C Shell Wrapper script for cat command in linux

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.

msrikanth
Newbie Poster
18 posts since Jan 2012
Reputation Points: 10
Solved Threads: 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.

LaMouche
Posting Whiz in Training
269 posts since Oct 2006
Reputation Points: 83
Solved Threads: 39
 

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.

msrikanth
Newbie Poster
18 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: