I found this link via google
this did not work for me, but the following did:
Code:
#!/bin/bash
cmp -s filename_1 filename_2 > /dev/null
if [ $? -eq 1 ]; then
echo is different
else
echo is not different
fi
It seems that diff might have not been returning the proper value, as its return code might mean simply whether or not it was able to read both files, instead of whether or not they are different, but i dont know
I was using fedora core 5 when i tried this, it failed, and i came up with the above code.
Just dont want someone in my shoes to come across this and get royally pwnd if/when the suggested solution fails
I wrote a script to convert .forward files into .procmailrc files so that my spamassassin does not get bypassed when people use vacation reply messages, because it seems .forward skips procmail processing, and so the user gets tons of spam while on vacation, and comes back with 300+ mailer-daemon messages saying their auto response failed to send, and any spams they did respond to that didnt fail most likely will mean more spam lists they've gotten themselves onto.
really all i was doing is checking all homedirs for .forward files, if it found any it would iterate thru them all, compare an existing .procmailrc if applicable to ":0 c" concatenated to the .forward file, and if different or non-exstant it would rewrite the file, if found and the same it would not.
it may be more efficient to just always delete and rewrite the file but if the user receives an email at the very instant between deletion and recreation there would be no .procmailrc file perhaps, and I am not about to test whether or not this can happen, so I am assuming it would.
if you want my whole file, here it is: (note: will only handle user dirs that are /home/USERNAME, will not handle any that are outside of this. i suppose you could parse /etc/passwd instead if you really wanted, but if you were going to get that good you might as well find a more elegant solution in the first place!)
Code:
#!/bin/bash
# this script removes .forward files and builds .procmailrc files as needed
# if .procmailrc doesnt exist or doesnt match with new .forward with ":0 c"
# then rebuild .procmailrc
for i in `ls -1 /home/*/.forward 2> /dev/null`
do
USERN=`echo $i | sed -e 's/\/home\///g' | sed -e 's/\/.forward//g'`
echo ":0 c" > /home/$USERN/.forw_proc_compare
cat /home/$USERN/.forward >> /home/$USERN/.forw_proc_compare
if [ -f /home/$USERN/.procmailrc ]; then
cmp -s /home/$USERN/.procmailrc /home/$USERN/.forw_proc_compare > /dev/null
if [ $? -eq 1 ]; then
echo "/home/$USERN/.procmailrc has changed, recreating"
rm -f /home/$USERN/.procmailrc
mv /home/$USERN/.forw_proc_compare /home/$USERN/.procmailrc
chmod 755 /home/$USERN/.procmailrc
chown $USERN:regular /home/$USERN/.procmailrc
else
rm -f /home/$USERN/.forw_proc_compare
fi
else
echo "/home/$USERN/.procmailrc doesnt exist, creating"
mv /home/$USERN/.forw_proc_compare /home/$USERN/.procmailrc
chmod 755 /home/$USERN/.procmailrc
chown $USERN:regular /home/$USERN/.procmailrc
fi
rm -f /home/$USERN/.forward
unset USERN
done;
this is kind of a crappy solution, but because our vacation response stuff is done thru webmin and I don't want to change the code incase someone ever updates it, suddenly the code wont work, so instead i am running an hourly cron. I could optionally run another script that checks for .forward files every 10 sec or something, then if it finds one, run this script on it, etc, but I didn't really need to.