Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a way to add a command to mail this if it finds any changes in the /newchanes.list. mail with an attachment(/changes) saying it found changes and if not then the subject line would say: no chanages has been made.

#!/bin/bash 

if [ ! -f "/suid.old" ]; then                          # note: ! 
   find / -perm -4000 -o -perm -2000 -ls > /suid.old   # note: dash before ls; slash before file 
else 
   find / -perm 4000 -o -perm -2000 -ls > /suid.new 
   diff /suid.old /suid.new > /newchanges.list 
   mv /suid.new /suid.old                              # could be handy 
fi
share|improve this question

2 Answers 2

You could do something like:

...
diff /suid.old /suid.new > /newchanges.list
if [ $? -eq 0 ]
then
    mail -s "No changed made" <email@domain.com>
else
    mail -s "Changes Found" <email@domain.com> < /newchanges.list
fi
...

diff exits with an exit code of 0 (at least on my ubuntu box, you should verify on your own system the exit codes) if no changes are found.

share|improve this answer
    
+1 Ya, this makes more sense, going to leave mine in case the exit status of diff doesn't always work like this. –  Kyle Brandt Feb 8 '10 at 19:42
    
You should just be able to if ! diff /suid.old ... –  Kyle Brandt Feb 8 '10 at 19:43

You can use the -s switch in a test to see if the resulting file is empty, if not than email. Might be a caveat to that method though...

   -s FILE
          FILE exists and has a size greater than zero
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.