| Current Path : /var/www/html/utils/ |
| Current File : /var/www/html/utils/findchange.sh |
#!/bin/bash
printf "***************************\n"
printf "* Find modified to txt,tar*\n"
printf "* --dir=your_dir *\n"
printf "* --day=modified_day *\n"
printf "* --to=text,tar *\n"
printf "* --exclude=text,tar *\n"
printf "***************************\n"
## variable to init
to="text"
while [ $# -gt 0 ]; do
case "$1" in
--dir=*)
dir="${1#*=}"
;;
--day=*)
day="${1#*=}"
;;
--exclude=*)
exclude="${1#*=}"
;;
--to=*)
to="${1#*=}"
;;
*)
printf "***************************\n"
printf "* Error: Invalid argument.*\n"
printf "***************************\n"
exit 1
esac
shift
done
IFS=', ' read -r -a array <<< "$exclude"
not_path='-path ./changes.tar.gz -o -path ./changes.log.txt '
var_i=0
for element in "${array[@]}"
do
#if [ $var_i -eq 0 ]
#then
# not_path+="-path '${element//,/}' "
#else
not_path+="-o -path '${element//,/}' "
#fi
var_i+=1
done
#echo "$dir"
#echo "$day"
#echo "$not_path"
findchanges(){
if [ $to == "tar" ]
then
eval "find $dir -mtime -$day -not \( $not_path \) -type f -print | tar -cvzf changes.tar.gz -T -"
else
eval "find $dir -mtime -$day -not \( $not_path \) -type f -print >> changes.log.txt"
fi
}
findchanges