#!/bin/bash SITE_IMAGE=$HOME/www/images #SITE_IMAGE_ALTERNATE=$HOME/www/images.sans_logos SITE_IMAGE_ALTERNATE=/backup ALL=img.txt echo "Generating listing of all files in $SITE_IMAGE_ALTERNATE ..." find ${SITE_IMAGE_ALTERNATE} -type f -print > site_alternate.cache while read id path do if [ ! -z "$path" -a "$path" != "NULL" ] then case $id in [0-9]*) if [ -f "${SITE_IMAGE}/$path" ] then result="OK" else found=$(cat site_alternate.cache | grep -- "$(echo $path | sed -e 's/\*/\\\*/g')\$" | head -1) if [ -z "$found" ] then # echo "grep pattern= $(echo $path | sed -e 's/\*/\\\*/g')\$" result="?" else result="FOUND IN $found" if [ ! -f "$found" ] then echo "cannot find $found" exit else target="${SITE_IMAGE}/$path" dir="$(dirname "$target")" [ -d "$dir" ] || mkdir -p "$dir" cp -p "$found" "$target" fi fi fi ;; *) result="not a product id"; esac printf "%-10s %-40s %s\n" "$id" "$path" "$result" fi done < ${ALL}