Jul 102017

Last night I uploaded my collect-certs code to Gitub.

Today, I discovered a problem with invoking mv on multiple files.

The code in question is around lines 40-42 and I’m including some of my debugging code here:

echo "Testing for existing directory '${CERT_DST_CERTS}/${cert}'"
if [ -d "${CERT_DST_CERTS}/${cert}" ]; then
    echo 'moving directory contents'
    echo doing this move: ${MV} -f "${TMP}/${cert}/*" "${CERT_DST_CERTS}/${cert}"
    ${MV} -f "${TMP}/${cert}/*" "${CERT_DST_CERTS}/${cert}/"
    ${RMDIR} ${TMP}/${cert}

When I run this script, I see this output:

Testing for existing directory '/var/db/certs-for-rsync/certs/example.com'
moving directory contents
doing this move: /bin/mv -f /var/db/certs-for-rsync/tmp/example.com/* /var/db/certs-for-rsync/certs/example.com
mv: rename /var/db/certs-for-rsync/tmp/example.com/* to /var/db/certs-for-rsync/certs/example.com/*: No such file or directory
rmdir: /var/db/certs-for-rsync/tmp/example.com: Directory not empty

Of note, that’s two errors: one from mv and the second from rmdir.

Now, if I manually run that command:

/bin/mv -f /var/db/certs-for-rsync/tmp/example.com/* /var/db/certs-for-rsync/certs/example.com

… it works. Go figure. Why?

I think the reason why is shown in the output. The destination directory ends with * but I sure didn’t put that in there. Why is this occurring?

Ummm, I found a solution, but I am not sure why it works.

    ${MV} -f ${TMP}/${cert}/* ${CERT_DST_CERTS}/${cert}

I am sure someone will tell me.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive