777 files and dir

i have four files that have 777 permission


find /var/tttt/ -type f -perm 0777

/var/ttt/1
/var/ttt/2
/var/ttt/3
/var/ttt/4

if any file other than above 4 have 777 permission then move that file to /garbage/yyyy-mmm-dd [2011-11-04]. Also email me that this have abcd have 777 permission.

Try this...

#!/bin/bash
DST_DIR=/garbage/$(date +%Y-%b-%d)
mkdir -p ${DST_DIR}
find /var/tttt/ -type f -perm 0777 ! -name "[1-4]" | while read line
do
        mv ${line} ${DST_DIR} && echo "${line} found with 777 permission" | mail you@you.com 
done

--ahamed

if ignore file (777 perm) have different name like


/var/ttt/xyz
/var/ttt/abcd
/var/ttt/d2g567
/var/ttt/4p987G

i want to ignore above file during moving, so how to do that.

You need to be specific. Which all files do you want to ignore?

--ahamed

brother your code is fine, but problem is that you mention [1-4] file name but i just checked that it have below files have 777, so i want below files to ignore list because that have 777 permission and i don't want to move these files, rest file that have 777 permission, i want to move to garbage directory as mentioned.


/var/ttt/1
/var/ttt/2
/var/ttt/3
/var/ttt/4
/var/ttt/xyz
/var/ttt/abcd
/var/ttt/d2g567
/var/ttt/4p987G

So, only these files with "specific" file names you want to ignore?

--ahamed

---------- Post updated at 12:38 AM ---------- Previous update was at 12:21 AM ----------

Try this...

#!/bin/bash
exclude="abcd|d2g567|4p987G"
DST_DIR=/garbage/$(date +%Y-%b-%d)
mkdir -p ${DST_DIR}
find /var/tttt/ -type f -perm 0777 ! -name "[1-4]" | while read line
do
        echo $line | egrep "(${exclude})" >/dev/null && continue
        mv ${line} ${DST_DIR} && echo "${line} found with 777 permission" | mail you@you.com 
done

--ahamed

1 Like

How to email the output to more than one user, please suggest.