0

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
Zypher
  • 37,405
  • 5
  • 53
  • 95

2 Answers2

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.

Zypher
  • 37,405
  • 5
  • 53
  • 95
0

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
Kyle Brandt
  • 83,619
  • 74
  • 305
  • 448