Sign up ×
Server Fault is a question and answer site for 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.


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

2 Answers 2

You could do something like:

diff /suid.old / > /newchanges.list
if [ $? -eq 0 ]
    mail -s "No changed made" <>
    mail -s "Changes Found" <> < /newchanges.list

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


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