Skip to content

Instantly share code, notes, and snippets.

@ednisley
Created June 21, 2018 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ednisley/ca7f1377d23eb9aafb4ebf80178fdf83 to your computer and use it in GitHub Desktop.
Save ednisley/ca7f1377d23eb9aafb4ebf80178fdf83 to your computer and use it in GitHub Desktop.
Bash script: copy action camera files using UUID / LABEL mounts
UUID=B40C6DD40C6D9262 /mnt/video ntfs noauto,uid=ed 0 0
UUID=0FC4-01AB /mnt/Fly6 vfat noauto,nodiratime,uid=ed 0 0
UUID=0000-0001 /mnt/M20 vfat noauto,nodiratime,uid=ed 0 0
LABEL=AS30V /mnt/AS30V exfat noauto,nodiratime,uid=ed 0 0
#!/bin/bash
# This uses too many bashisms for dash
thisdate=$(date --rfc-3339=date)
echo Date is $thisdate
date
# MicroSD / readers / USB drive defined in fstab
# ... with UUID or PARTID as appropriate
echo Mounting bulk video drive
sudo mount /mnt/video
if [ $? -ne 0 ]; then
echo '** Cannot mount video storage drive'
exit
fi
# Show starting space available
df -h /mnt/video
#-- Sony AS30V
printf "\n--- AS30V\n"
as30v=/mnt/AS30V
sudo mount $as30v
if [ $? -eq 0 ]; then
echo " start AS30V transfer on $as30v"
mkdir /mnt/video/AS30V/$thisdate
rsync -ahu --progress --exclude "*THM" $as30v/MP_ROOT/100ANV01/ /mnt/video/AS30V/$thisdate &
pid1=$!
echo " PID is $pid1"
else
echo " skipping"
as30v=
fi
#-- Cycliq Fly6
printf "\n--- Fly6\n"
fly6=/mnt/Fly6
sudo mount $fly6
if [ $? -eq 0 ]; then
echo " start Fly6 transfer on $fly6"
rsync -ahu --progress $fly6 /mnt/video &
pid2=$!
echo " PID is $pid2"
else
echo " skipping"
fly6=
fi
#-- SJCAM M20
printf "\n--- M20\n"
m20=/mnt/M20
sudo mount $m20
if [ $? -eq 0 ]; then
echo " start M20 transfer on $m20"
mkdir /mnt/video/M20/$thisdate
# See if any still images exist to avoid error messages
n=$( ls $m20/DCIM/Photo/* 2> /dev/null | wc -l )
if [ $n -gt 0 ] ; then
echo " copy M20 photos first"
rsync -ahu --progress $m20/DCIM/Photo/ /mnt/video/M20/$thisdate
fi
rsync -ahu --progress $m20/DCIM/Movie/ /mnt/video/M20/$thisdate &
pid3=$!
echo " PID is $pid3"
else
echo " skipping"
m20=
fi
printf "\n----- Waiting for all rsync terminations\n"
rc=0
for p in $pid1 $pid2 $pid3 ; do
wait -n
rc=$(( rc+$? ))
echo RC so far: $rc
done
date
if [ $rc -eq 0 ] ; then
echo '----- Final cleanups'
echo Fix capitalized extensions
find /mnt/video -name \*AVI -print0 | xargs -0 rename -v -f 's/AVI/avi/'
find /mnt/video -name \*MP4 -print0 | xargs -0 rename -v -f 's/MP4/mp4/'
if [ "$as30v" ]; then
echo Remove files on $as30v
rm $as30v/MP_ROOT/100ANV01/*
sudo umount $as30v
fi
if [ "$fly6" ]; then
echo Remove files on $fly6
rm -rf $fly6/DCIM/*
sudo umount $fly6
fi
if [ "$m20" ]; then
echo Remove files on $m20
rm $m20/DCIM/Movie/* $m20/DCIM/Photo/*
sudo umount $m20
fi
echo '----- Space remaining on video drive'
df -h /mnt/video
sudo umount /mnt/video
echo Done!
else
echo Whoopsie! Total RC: $rc
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment