#!/bin/sh # Kludgy shell script to simulate "pvfs2-cp -r source(s) destination" # until the real "pvfs2-cp" command supports a "-r" option # # Mark Bartelt # Caltech/CACR # March 2006 PATH=/usr/local/pvfs2/bin:$PATH; export PATH case $# in 0|1) echo "Usage: $(basename $0) src [src ...] dst" >&2; exit 1 ;; *) ;; esac src_list=$( echo $@ | awk '{ for ( n=1; n&2; exit 1; } for src in ${src_list}; do # First, confirm that the file exists if test ! -e ${src}; then echo "${src} doesn't exist!" >&2 # If it does, and is a regular file, just copy it elif test -f ${src}; then pvfs2-cp ${src} ${dst}/$(basename ${src}) # If it's not a regular file, check whether it's # a directory; if it is, things get somewhat more # complicated: We first create all the necessary # directories on the destination side, then copy # each individual file. elif test -d ${src}; then ( dir=$( basename ${src} ) cd $( dirname ${src} ) || exit 1 dir_list=$( find ${dir} -type d -print ) file_list=$( find ${dir} -type f -print ) ( cd ${dst} && mkdir -p ${dir_list} ) for file in ${file_list}; do pvfs2-cp ${file} ${dst}/${file} done ) # If it's something other than a regular file or a # directory, just note its presence with a message else echo "${src} is neither a directory nor a regular file; ignoring" >&2 fi done