#!/bin/bash


drive="/mnt/media"

for dir in "$drive"/*; do

    if [ -d "$dir" ]; then

    #echo "$dir"

        for pid in "$dir"/*; do

            if [ -d "$pid" ]; then

            #echo "$pid"

                for folder in "$pid"*/photos; do

                if [ -d "$folder" ]; then

                #echo "$folder"

		if [ -f "${folder}/${pid##*/}_1.jpg" ] ; then

		echo "photo exist ${pid##*/}_1.jpg"
		sudo convert "${folder}/${pid##*/}_1.jpg" -resize 800x "${folder}/${pid##*/}_thumb.jpg"

		fi

                fi
            done

            fi
        done

    fi
done
