#!/bin/bash # Creating an arrays of home directory files: webdir="testdir/website/" homedir="testdir/home/" young_files=() while IFS= read -r -d $'\0'; do young_files+=("$REPLY") done < <(find $homedir -mindepth 1 -maxdepth 1 -type f -ctime -14 -name "*.zip" -print0) old_files=() while IFS= read -r -d $'\0'; do old_files+=("$REPLY") done < <(find $webdir* -mindepth 1 -maxdepth 1 -type f -ctime +14 -name "*.zip" -print0) echo " --- Young files ---" for file in "${young_files[@]}"; do filename=$(basename "$file") checksum=$(md5sum "$file" | awk '{print $1;}') filesite=$webdir$checksum if mkdir "$filesite" ; then echo "Made directory, and it worked!" webpage=$filesite/index.html cat html/1.part >> $webpage echo \\$filename\\ >> $webpage cat html/2.part >> $webpage stat $file >> $webpage zipinfo -1 $file | tree --fromfile . >> $webpage cat html/3.part >> $webpage mv "$file" "$filesite/$filename" else echo "Already done." fi echo "file: $file" echo "filename: $filename" echo "checksum: $checksum" done echo "\n --- Old files ---" for file in "${old_files[@]}"; do filename=$(basename "$file") checksum=$(md5sum "$file" | awk '{print $1;}') echo "file: $file" echo "filename: $filename" echo "checksum: $checksum" rm -rf $(dirname "$file") done