SOURCE="/media/Iomega"
DEST="/home"
echo_date_do() {
cmd=$*
eval "$cmd" && echo "$(date) : $cmd"
}
[ -n "$1" -a -n "$2" ] && SOURCE="$1" && DEST="$2"
if [ -r "$SOURCE" -a -d "$SOURCE" -a -r "$DEST" -a -d "$DEST" ]; then
for file in $(find "$SOURCE" -type f -name "*.jpg" -print); do
bn=$(basename "$file")
if [ -f "${DEST}/$bn" -a $(stat -c%s "$file") -eq $(stat -c%s "${DEST}/$bn") ]; then
echo_date_do 'mv "${DEST}/$bn" "${DEST}/${bn}0"'
fi
echo_date_do 'cp "$file" "$DEST"'
done
exit 0
else
exit 1
fi
imgbkup >"/home/logs/imgbkup/$(date -I'seconds')-imgbkup.log"
find . -type f -name "*.jpg" -print | while read i; do
if [ -f "/home/$i" ]; then
echo SAME NAME
j="/home/$i"
filesize_new=$(stat -c%s "$i")
filesize_old=$(stat -c%s "$j")
if [ $filesize_new == $filesize_old ]; then
echo AND SAME SIZE
else
echo echo BUT NOT SAME PICTURE
mv "$j" "$j"0
cp "$i" /home/
fi
else
echo OK YOU CAN DIRECT COPY
cp "$i" /home/
fi
done
SOURCE="/media/Iomega"
DEST="/home"
case "$1" in
--help)
echo 'Usage : '$(basename "$0")'[--overwrite] [source-directory destination-directory]' && exit 0
break;;
--overwrite) OVERWRITE='true'; shift; break;;
*) OVERWRITE='false';;
esac
[ -n "$1" -a -n "$2" ] && SOURCE="$1" && DEST="$2"
if [ -r "$SOURCE" -a -d "$SOURCE" -a -r "$DEST" -a -d "$DEST" ]; then
find "$SOURCE" -type f -name "*.jpg" -print | while read $file; do
bn=$(basename "$file")
if [ -f "${DEST}/$bn" -a $(stat -c%s "$file") -eq $(stat -c%s "${DEST}/$bn") ]; then
case $OVERWRITE in
true) rm -f ${DEST}/$bn;;
false) mv "${DEST}/$bn" "${DEST}/${bn%%.jpg}_$(cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 8).jpg";;
esac
fi
cp "$file" "$DEST"
done
exit 0
else
exit 1
fi
date '+%Y%m%e-%H%M%S'
cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 8
if [ -f "${DEST}/$bn" -a $(stat -c%s "$file") -eq $(stat -c%s "${DEST}/$bn") ]; then
case $OVERWRITE in
true) rm -f ${DEST}/$bn;;
false) mv "${DEST}/$bn" "${DEST}/${bn%%.jpg}_$(cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 8).jpg";;
esac
fi
if [ -f "${DEST}/$bn" ] && [ $(stat -c%s "$file") -ne $(stat -c%s "${DEST}/$bn") ]; then
#!/bin/sh
# Default values.
SOURCE="/media/Iomega"
DEST="/home"
SEARCH="*.jpg *.png"
OVERWRITE='false'
# Print help if requested and look for arguments in command line.
for i in $(seq 1 2); do
case "$1" in
--help)
echo 'Usage : '$(basename "$0")'[--overwrite] [--search "pattern1 pattern2" ] [source-directory destination-directory]'
exit 0
;;
--overwrite)
OVERWRITE='true' && shift
;;
--search)
SEARCH="$2" && shift 2
;;
*) ;;
esac
done
[ -n "$1" -a -n "$2" ] && SOURCE="$1" && DEST="$2"
# Execute the script.
if [ -r "$SOURCE" -a -d "$SOURCE" -a -r "$DEST" -a -d "$DEST" ]; then
# Set -f disable pathname expansion (globbing).
set -f
if [ "${SEARCH%% *}" = "$SEARCH" ]; then
command='find $SOURCE -name "'$SEARCH'"'
else
command='find $SOURCE -name "'${SEARCH%% *}'"'$(for i in ${SEARCH#* }; do echo -n " -o -name \"$i\""; done)
fi
set +f
# Run the main loop.
eval "$command" | while read file; do
bn=$(basename "$file")
bc=$(stat -c%s "$file")
if [ -f "${DEST}/$bn" ] && [ "$bc" -ne $(stat -c%s "${DEST}/$bn") ]; then
case $OVERWRITE in
true)
echo "Removing ${DEST}/$bn"
rm -f "${DEST}/$bn"
if [ -f "${DEST}/$bn.$bc" ]; then
echo "Moving ${DEST}/$bn.$bc to ${DEST}/$bn"
mv "${DEST}/$bn.$bc" "${DEST}/$bn"
fi
;;
false)
bn="$bn.$bc"
;;
esac
fi
if [ -f "${DEST}/$bn" ]; then
echo "File ${DEST}/$bn already exists."
else
echo "Copying $file to $DEST/$bn"
cp -a "$file" "$DEST/$bn"
fi
done
exit 0
else
echo "Error : Can't find $SOURCE or $DEST"
exit 1
fi
scriptname /media/Iomega HDD dest
scriptname "/media/Iomega HDD" dest
#!/bin/sh
# Default values.
SOURCE="/media/Iomega"
DEST="/home"
SEARCH="*.jpg *.png"
OVERWRITE='false'
# Print help if requested and look for arguments in command line.
for i in $(seq 1 2); do
case "$1" in
--help)
echo 'Usage : '$(basename "$0")'[--overwrite] [--search "pattern1 pattern2" ] [source-directory destination-directory]'
exit 0
;;
--overwrite)
OVERWRITE='true' && shift
;;
--search)
SEARCH="$2" && shift 2
;;
*) ;;
esac
done
[ -n "$1" -a -n "$2" ] && SOURCE="$1" && DEST="$2"
# Execute the script.
if [ -r "$SOURCE" -a -d "$SOURCE" -a -r "$DEST" -a -d "$DEST" ]; then
# Set -f disable pathname expansion (globbing).
set -f
if [ "${SEARCH%% *}" = "$SEARCH" ]; then
command="find \"$SOURCE\" -name \"$SEARCH\""
else
command="find \"$SOURCE\" -name \"${SEARCH%% *}\""$(for i in ${SEARCH#* }; do echo -n " -o -name \"$i\""; done)
fi
set +f
# Run the main loop.
eval "$command" | while read file; do
bn=$(basename "$file")
bc=$(stat -c%s "$file")
if [ -f "${DEST}/$bn" ] && [ "$bc" -ne $(stat -c%s "${DEST}/$bn") ]; then
case $OVERWRITE in
true)
echo "Removing ${DEST}/$bn"
rm -f "${DEST}/$bn"
if [ -f "${DEST}/$bn.$bc" ]; then
echo "Moving ${DEST}/$bn.$bc to ${DEST}/$bn"
mv "${DEST}/$bn.$bc" "${DEST}/$bn"
fi
;;
false)
bn="$bn.$bc"
;;
esac
fi
if [ -f "${DEST}/$bn" ]; then
echo "File ${DEST}/$bn already exists."
else
echo "Copying $file to $DEST/$bn"
cp -a "$file" "$DEST/$bn"
fi
done
exit 0
else
echo "Error : Can't find $SOURCE or $DEST"
exit 1
fi
# Set -f disable pathname expansion (globbing).
set -f
if [ "${SEARCH%% *}" = "$SEARCH" ]; then
command="find \"$SOURCE\" -name \"$SEARCH\""
else
command="find \"$SOURCE\" -name \"${SEARCH%% *}\""$(for i in ${SEARCH#* }; do echo -n " -o -name \"$i\""; done)
fi
set +f
It looks like you're new here. If you want to get involved, click one of these buttons!