aboutsummaryrefslogtreecommitdiffstats
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
parentc6fc72134f3e11bab508e6bc01517d4e6804bc01 (diff)
scripts from laptop for copying and syncing pictures from camera and a script for killing a process at a specific time
-rwxr-xr-xcopy_camsd.sh135
-rwxr-xr-xrsync_pics.sh37
-rwxr-xr-xtimeKill.sh106
3 files changed, 278 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
diff --git a/rsync_pics.sh b/rsync_pics.sh
new file mode 100755
index 0000000..a44c262
--- /dev/null
+++ b/rsync_pics.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+usage() {
+ echo "Usage: $0 [-v] [-l]"
+ exit 0
+}
+
+### default values ###
+
+# folder for pictures
+picdir="/home/lookshe/Bilder/d5100"
+
+# server path #
+serverpath="192.168.1.33:/home/lookshe/bilder/"
+
+nicelevel=19
+
+verbose=0
+bwlimit=0
+
+# parse arguments #
+for arg in "$@"
+do
+case $arg in
+ -v)
+ verbose=1
+ ;;
+ -l)
+ bwlimit=1
+ ;;
+ *)
+ usage
+ ;;
+esac
+done
+
+nice -n $nicelevel rsync -a -r $(if [ $verbose -eq 1 ]; then echo "-v"; fi) $(if [ $bwlimit -eq 1 ]; then echo "--bwlimit 1000"; fi) --progress "$picdir" "$serverpath"
diff --git a/timeKill.sh b/timeKill.sh
new file mode 100755
index 0000000..cd3f0ec
--- /dev/null
+++ b/timeKill.sh
@@ -0,0 +1,106 @@
+#/bin/bash
+
+ende() {
+ printf "\b \b"
+ echo "$0 cancelled"
+ # show input again
+ stty echo
+ exit 10
+}
+
+trap ende 2
+
+usage() {
+ echo "usage: $0 (processname|pid) time(hh:mm)"
+ exit 1
+}
+
+output() {
+ if [ $# -eq 1 ]
+ then
+ printf "$1"
+ sleep 3
+ printf "\b \b"
+ fi
+}
+
+rotate() {
+ rotate_help
+ rotate_help
+}
+
+rotate_help() {
+ output "|"
+ output "/"
+ output "-"
+ output "\\"
+}
+
+# exit if not 2 arguments are given
+if [ $# -ne 2 ]
+then
+ usage
+fi
+
+process="$1"
+time="$2"
+actTime="$(date +%H:%M)"
+# exit if given time is not correct
+if [ "$(echo "$time" | sed 's/[01][0123456789]:[012345][0123456789]\|[2][0123]:[012345][0123456789]//g')" != "" ]
+then
+ usage
+fi
+
+# select if PID or processname is given
+# hopefully no process is named only with numbers
+if [ "$(echo "$process" | sed s/[0123456789]//g)" = "" ]
+then
+ isPID="true"
+else
+ isPID="false"
+fi
+
+# exit if processname or PID is not single-valued
+if [ $(ps -A | grep $process | wc -l) -ne 1 ]
+then
+ echo "no process found or too many found! ($process)"
+ exit 2
+fi
+
+# convert processname to PID if neccessary
+if [ "$isPID" = "false" ]
+then
+ process="$(ps -A | grep $process | awk '{print $1}')"
+fi
+
+# turn of showing input
+stty -echo
+
+# endless loop ;-)
+while [ 1 ]
+do
+ # exit if process already stopped
+ if [ $(ps -A | awk '{print $1}' | grep $process | wc -l) -ne 1 ]
+ then
+ echo
+ echo "process already stopped"
+ stty echo
+ exit 0
+ fi
+
+ # if time has reached, then kill process and exit
+ if [ "$actTime" = "$time" ]
+ then
+ kill "$process"
+ echo
+ echo "process killed succesfully"
+ stty echo
+ exit 0
+ # output to see that the script works
+ # checks every 48 sec
+ else
+ rotate
+ rotate
+ fi
+ actTime=$(date +%H:%M)
+done