Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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

    Srikanth M.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    I/O redirection are handled at the top-most level shell, and don't propagate to your script. To do what you want will require some C or C++ coding I think, in that you will need to capture stdin/stdout targets directly. It may be doable in CSH, but I don't know for sure if that is possible... too many years since I last wrote a lot of csh code.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts