aboutsummaryrefslogtreecommitdiffstats
path: root/copy_camsd.sh
diff options
context:
space:
mode:
authorlookshe <lookshe@lookshe-laptop.(none)>2014-09-21 00:17:28 +0200
committerlookshe <lookshe@lookshe-laptop.(none)>2014-09-21 00:17:28 +0200
commitce0e78eaeb3b2311327505789e7d56f89711add1 (patch)
treea4762905beb66cdedccb7d09cf2d9b7fe848e0cc /copy_camsd.sh
parentc6fc72134f3e11bab508e6bc01517d4e6804bc01 (diff)
scripts from laptop for copying and syncing pictures from camera and a script for killing a process at a specific time
Diffstat (limited to 'copy_camsd.sh')
-rwxr-xr-xcopy_camsd.sh135
1 files changed, 135 insertions, 0 deletions
diff --git a/copy_camsd.sh b/copy_camsd.sh
new file mode 100755
index 0000000..7c8e6ab
--- /dev/null
+++ b/copy_camsd.sh
@@ -0,0 +1,135 @@
+#!/bin/bash
+
+usage() {
+ echo "Usage: $0 [--dev device] [--deleteaftercopy] [--noraw] [--nojpg] [--nomov] [--notimeinstamp]"
+ exit 0
+}
+
+### default values ###
+
+# device #
+sddev=/dev/mmcblk0p1
+
+# folder for pictures
+picdir="/home/lookshe/Bilder/d5100"
+
+# file endings #
+end_jpg=".JPG"
+end_raw=".NEF"
+end_mov=".MOV"
+
+# delete and timestamp #
+deleteaftercopy=0
+notimeinstamp=0
+
+# which to copy #
+copyraw=1
+copyjpg=1
+copymov=1
+
+# we work with nice #
+nicelevel=19
+
+# parse arguments #
+#for arg in "$@"
+while [ "$1" != "" ]
+do
+case $1 in
+ --deleteaftercopy)
+ deleteaftercopy=1
+ ;;
+ --noraw)
+ copyraw=0
+ ;;
+ --nojpg)
+ copyjpg=0
+ ;;
+ --nomov)
+ copymov=0
+ ;;
+ --notimeinstamp)
+ notimeinstamp=1
+ ;;
+ --dev)
+ shift
+ sddev="$1"
+ ;;
+ *)
+ usage
+ ;;
+esac
+shift
+done
+
+# check for inserted card #
+if [ ! -e "$sddev" ]
+then
+ echo "sd card not inserted!"
+ exit 1
+fi
+
+# check if mounted #
+#mountpoint=$(mount | grep "$sddev" | awk '{print $3}')
+mountpoint=$(mount | grep "$sddev" | cut -d" " -f3- | sed 's/ type.*//')
+if [ ! -e "$mountpoint" ]
+then
+ echo "sd card not mounted!"
+ exit 2
+fi
+
+if [ $notimeinstamp -eq 1 ]
+then
+ stamp=$(date +%F)
+else
+ stamp=$(date +%F_%H-%M)
+fi
+copydir="$picdir/$stamp"
+
+if [ -e "copydir" ]
+then
+ echo "$copydir already exists"
+ exit 3
+else
+ mkdir "$copydir"
+fi
+
+echo "Start copying files:"
+
+if [ $copyjpg -eq 1 ]
+then
+ mkdir "$copydir/pic"
+ find "$mountpoint" -name "*$end_jpg" | while read file
+ do
+ nice -n $nicelevel cp -v "$file" "$copydir/pic"
+ if [ $? -eq 0 -a $deleteaftercopy -eq 1 ]
+ then
+ nice -n $nicelevel rm "$file"
+ fi
+ done
+fi
+
+if [ $copyraw -eq 1 ]
+then
+ mkdir "$copydir/raw"
+ find "$mountpoint" -name "*$end_raw" | while read file
+ do
+ nice -n $nicelevel cp -v "$file" "$copydir/raw"
+ if [ $? -eq 0 -a $deleteaftercopy -eq 1 ]
+ then
+ nice -n $nicelevel rm "$file"
+ fi
+ done
+fi
+
+if [ $copymov -eq 1 ]
+then
+ mkdir "$copydir/mov"
+ find "$mountpoint" -name "*$end_mov" | while read file
+ do
+ nice -n $nicelevel cp -v "$file" "$copydir/mov"
+ if [ $? -eq 0 -a $deleteaftercopy -eq 1 ]
+ then
+ nice -n $nicelevel rm "$file"
+ fi
+ done
+fi