#!/bin/sh

OLD=${1?old directory not specified}
NEW=${2?new directory not specified}
MERGE=${3?merge directory not specified}

for host in $(ls "$OLD"); do
    echo "Merging RRDs for ${host}"

    for rrdpath in $OLD/$host/*.rrd; do
        rrdname=${rrdpath#$OLD/$host/}
        rrdpathnew="${NEW}/$host/$rrdname"
        if [[ ! -e "${rrdpathnew}" ]]; then
            continue
        fi
        echo -e "\t$rrdname"
        ./rrdmerge $rrdpath $rrdpathnew $rrdpathnew
    done
done
