#!/bin/bash

#
#Vars
#

server[0]=/home/gs/server1
server[1]=/home/gs/server2
server[2]=
server[3]=

days_log=7
days_log_gz=14
days_downloads=7

clean_logs=1
clean_downloads=1
clean_ztmp=1
clean_broken_links=0


#
#Programm-Start
#

for dir in ${server[*]}; do
[[ ! -d $dir ]] && echo "Directory $dir doesn't exist, please correct the variables server[x] in the Script." && fail=1
done

[[ "$fail" = "1" ]] && echo "Script aborted" && exit

[[ "$clean_logs" = "1" ]] && echo "Gzip *.log older than $days_log days" && find ${server[*]} -type f -path "*/logs/*" -name "*.log" -mtime +$days_log -exec nice gzip '{}' \;
[[ "$clean_logs" = "1" ]] &&  echo "Deleting *.log.gz older than $days_log_gz days" && find ${server[*]} -type f -path "*/logs/*" -name "*.log.gz" -mtime +$days_log_gz -delete
[[ "$clean_ztmp" = "1" ]] && echo "Deleting *.ztmp (*.dat.zmtp is excluded)" && find ${server[*]} -name *.ztmp -not -name *.dat.ztmp -delete
[[ "$clean_downloads" = "1" ]] && echo "Deleting downloads, which are older then $days_downloads days" && find ${server[*]} -type f -name ????????.dat* -path "*/downloads/*" -mtime +$days_downloads -delete
[[ "$clean_broken_links" = "1" ]] && echo "Deleting broken symlinks" && find -L ${server[*]} -type l -delete