Jeff, Mike, and all,
I would like to apologize for sending an older version of my twhelp.sh
script than intended. Both Mike and Jeff have offered good alternative
fixes for the version I sent. To help avoid any further confusion I am
including a known working version of twhelp.sh. Thank you Mike and Jeff
for your comments. I am in the process of working on a newer version
that should improve performance, and will post it to the list when
completed. I will also make note that if you run this script on Solaris
you will need to change line 37 to read:
correct_type="ascii"
as Solaris evaluates
eval file $1 | awk '{ print $2 }'
to all lower case output.
Again sorry for the confusion. Any and all comments are welcome.
----------------------------------------------------------------------
#! /bin/bash
#
# twhelp version 4
#
#############################################################
# #
# Christopher Cuevas #
# [EMAIL PROTECTED] #
# Nov. 15th 2002 #
# Florida Center for Library Automation #
# #
# twhelp will comment out lines from a twpol.txt file when #
# supplied with a twreport_file and the path to twpol.txt #
# and create a twpol.txt.fixed file #
# #
# usage: twhelp twreport_file path_to_twpol.txt #
# #
#############################################################
E_NOARGS=65
E_ARGERROR=66
if [ $# -eq 0 ]
then
echo "Usage: `basename $0` twreport_file path/to/twpol.txt" >&2
# Error message to stderr
exit $E_ARGERROR
fi
# Test for correct file type
type=`eval file $1 | awk '{ print $2 }'`
# "file $1" echos file type...
# then awk removes all but the second field
# the result is fed into the variable "type" and compared to
"correct_type"
correct_type="ASCII"
if [ "$type" != "$correct_type" ]
then
echo
echo "This script only works on non executable ascii files."
echo
fi
cat "$1" | grep Filename: | awk -F: '{ print $2 }' > tmp.fix1
# awk through the twreport file and create a tmp.fix1
# file with all paths to files that are not on the system
sed 's/\//\\\//g' tmp.fix1 > tmp.fix2
# add a \ in front of the path so sed will comment it out correctly
# output this to tmp.fix2
cp -p $2 tmp.fix1
# copy twpol.txt over tmp.fix1 so as not to mess with the original
# twpol.txt file. we were done with that version of tmp.fix1 anyway.
for line in `cat tmp.fix2`
do
sed "s/.*$line/# &/" "tmp.fix1" > twpol.txt.fixed
cp twpol.txt.fixed tmp.fix1
done
# comment out lines from twpol.txt(aka tmp.fix1)
# and create twpol.txt.fixed
rm -rf tmp.fix1
rm -rf tmp.fix2
# clean up the tmp.fix files
exit 0
-------------------------------------------------------------------------
On Thu, 2003-01-23 at 16:14, Mike Vanecek wrote:
> fixed="twpol.txt.fixed"
> fixedtmp="tmp.fixed"
> cp $2 $fixedtmp
> ls -al $fixedtmp
> for line in `cat tmp.fix2`
> do
> # echo $line
> # sed "s/.*$line/# &/" "$2" > twpol.txt.fixed
> sed "s/.*$line/# &/" "$fixedtmp" > twpol.txt.fixed
> cp twpol.txt.fixed tmp.fixed
> ls -al $fixedtmp
> ls -al $fixed
> # echo $2
> done
>
> I believe the problem is that
>
> sed "s/.*$line/# &/" "$2" > twpol.txt.fixed
>
> this line overwrote the fixed file everytime and thus the result was
that only
> the last item in tmp.fix2 was recorded.
>
> My snipet above illustrates the problem and has a not so pretty fix -
I think?
> Subject: RE: Tripwire
> Date: Fri, 24 Jan 2003 13:23:09 +0800
> From: "Turner, (Resolute Address) Jeff" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Reply-To: [EMAIL PROTECTED]
>
> I have a redhat server which runs tripwire but was giving me the long list of
>missing files in every report. After reading this thread I thought it would be a good
>idea to implement the script written by Chris, BUT I found that as posted it only
>updated the policy with the LAST line of missing files.
>
> The section
>
> for line in `cat tmp.fix2`
> do
> sed "s/.*$line/# &/" "$2" > twpol.txt.fixed
> done
>
> replaces twpol.txt.fixed each time through the loop.
>
> I replaced this with
>
> for line in `cat tmp.fix2`
> do
> echo "s/.*$line/# &/" >> tmp.fix3
> # create a list of substitutions for sed to perform
> done
>
> sed -f tmp.fix3 "$2" > twpol.txt.fixed
> # Run sed commenting out ALL missing files from the list
> rm -rf tmp.fix3
>
> I know this could have been done when te tmp.fix2 file was created but this was
>easier for me to write and as it is a script that will only be run once per machine
>it didnt seem worth worrying too much about efficiency.
>
> I would have used the Perl script also submitted but as it was sent as an attachment
>and I get the list in digest format I couldn't (easily) get it.
>
> I ran the shell script and now my tripwire reports 0 errors !
>
--
_ _ _ _
o' \,=./ `o o' \,=./ `o
(o o) (o o)
+-------oo0--(_)--0oo-------------------------------ooO--(_)--Ooo---+
| |
| Christopher Cuevas [EMAIL PROTECTED] |
| |
+-------------------------------------------------------------------+
F l o r i d a C e n t e r f o r L i b r a r y A u t o m a t i o n
| 0ooo ooo0 0ooo |
+------ooo0---( )-----------------------------------( )---( )----+
( ) )/ "Why waste time learning, \( )/
\( (/ when ignorance is instantaneous?" - Calvin
\)
--
Psyche-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/psyche-list