binaryDigit
03-25-2001, 02:35 PM
#!/bin/sh
# using month and day from date. month is $2 and day is $3
set $(date)
# file variables
temp="/home/phil/fw_hits/temp_diff/temp"
hits="/home/phil/fw_hits/fw_hits_$2_$3"
difx="/home/phil/fw_hits/temp_diff/difx"
owner="phil:users"
# run the filter on /var/log/messages grep Packet log: will give us any firewall hits
# grep "$2 $3" will exclude the firewall hits we get by the current day and month
# outputting to a temp file
cat /var/log/messages | grep 'Packet log:' | grep "$2 $3" > $temp
# if the temp file has a non-zero size we know we had a firewall hit
# otherwise we won't continue
if [ -s $temp ]; then
# if a hits file for the current day already exists then
# check to see if temp has more firewall hits than what
# is already in hits file
if [ -e $hits ]; then
diff $temp $hits > $difx
if [ -s $difx ]; then
# copy the temp file to the hits file if temp sees firewall hits
cp $temp $hits
# if this is run in ip-down then the file will be owned by root
# so change ownership so i don't have to su
chown $owner $hits
# there are firewall hits for the current day so let me know
echo -e \\a
fi
else
touch $hits
# copy the temp file to the hits file if temp sees firewall hits
cp $temp $hits
# if this is run in ip-down then the file will be owned by root
# so change ownership so i don't have to su
chown phil:users $hits
# there are firewall hits for the current day so let me know
echo -e \\a
fi
fi
# not going to remove temp file in any situation because it's just going to be used again.
# -binaryDigit
ok my question is how can i check for the size of a file. what i am trying to do is make sure that if i've already
got firewall hits for a certain day/month that i only copy the temp file to it if there are more firewall hits.
i made it work by outputting a diff operation to a file and checking for a non-zero size on the file. i was just wondering if there was a better way.
# using month and day from date. month is $2 and day is $3
set $(date)
# file variables
temp="/home/phil/fw_hits/temp_diff/temp"
hits="/home/phil/fw_hits/fw_hits_$2_$3"
difx="/home/phil/fw_hits/temp_diff/difx"
owner="phil:users"
# run the filter on /var/log/messages grep Packet log: will give us any firewall hits
# grep "$2 $3" will exclude the firewall hits we get by the current day and month
# outputting to a temp file
cat /var/log/messages | grep 'Packet log:' | grep "$2 $3" > $temp
# if the temp file has a non-zero size we know we had a firewall hit
# otherwise we won't continue
if [ -s $temp ]; then
# if a hits file for the current day already exists then
# check to see if temp has more firewall hits than what
# is already in hits file
if [ -e $hits ]; then
diff $temp $hits > $difx
if [ -s $difx ]; then
# copy the temp file to the hits file if temp sees firewall hits
cp $temp $hits
# if this is run in ip-down then the file will be owned by root
# so change ownership so i don't have to su
chown $owner $hits
# there are firewall hits for the current day so let me know
echo -e \\a
fi
else
touch $hits
# copy the temp file to the hits file if temp sees firewall hits
cp $temp $hits
# if this is run in ip-down then the file will be owned by root
# so change ownership so i don't have to su
chown phil:users $hits
# there are firewall hits for the current day so let me know
echo -e \\a
fi
fi
# not going to remove temp file in any situation because it's just going to be used again.
# -binaryDigit
ok my question is how can i check for the size of a file. what i am trying to do is make sure that if i've already
got firewall hits for a certain day/month that i only copy the temp file to it if there are more firewall hits.
i made it work by outputting a diff operation to a file and checking for a non-zero size on the file. i was just wondering if there was a better way.