#!/bin/sh SRC="$1" DST="$2" # Check input parameters if [ $# -lt 2 ]; then echo "$0 " exit 2 fi # Check that the source file exists if [ ! -e $SRC ]; then echo "$SRC not found" exit 2 fi if [ ! -e $DST ]; then echo "cp $SRC $DST" cp $SRC $DST else # Check that we have the 'stat' binary. If not, we don't do the copy. which stat > /dev/null if [ $? -eq 1 ]; then echo "warning: stat not found, no comparison can be made" exit 0 fi SRCT=$(stat -c %Y $SRC) DSTT=$(stat -c %Y $DST) if [ $DSTT -lt $SRCT ]; then echo "cp $SRC (time=$SRCT) $DST (time=$DSTT)" cp -f $SRC $DST fi fi