Hello, On Thu, 29 Sep 2011, David C. Rankin wrote:
On 09/29/2011 01:40 PM, David C. Rankin wrote:
dnh, all see any holes in it or a way to make it better? I was just going to throw it an a function and write it out...
Just FYI, here is what I ended up with. I added an intermediate tmp file to strip the \r:
#!/bin/bash
## dir test [[ -d /dat_e/dv/new ]] || { echo "No /dat_e/dv/new, exiting..."; exit 2; }
I prefer to use the simple test -d /dat_e/dv/new || { echo "No /dat_e/dv/new, exiting..."; exit 2; }
cd /dat_e/dv/new || { echo "cannot change into /dat_e/dv/new, exiting..."; exit 2; }
You could simply change to the dir, you'll get a fitting message: $ cd /dat_e/dv/new bash: cd: /dat_e/dv/new: No such file or directory i.e. just use cd /dat_e/dv/new || exit 2 instead of above two tests.
## read tape count and set up vars & tmp files tapect=${1:-$(</dat_e/dv/tapect.txt)} tmpfn=/tmp/dvtmp.log tmpapp=/tmp/dvapp.log :>$tmpfn :>$tmpapp first_dt="" last_dt=""
## fix date format from yyyy.mm.dd to mm/dd/yyyy fixdfmt() { [[ -n $1 ]] || { echo "ERROR: Nothing passed to function 'fixdfmt'"; return 1; } year=${1//.*} day=${1##*.} mo=${1%.*} mo=${mo##*.} echo "${mo}/${day}/${year}" return 0 }
An fun alternative I came up with: fixdfmt() { test -z "$1" && { echo "ERROR: Nothing passed to function 'fixdfmt'" >&2; return 1; } _fixdfmt() { echo "$3/$2/$1"; } oIFS="$IFS"; IFS="." _fixdfmt $1 IFS="$oIFS" # unset _fixedfmt }
## parse dates from $tmpfn to get start and end dates for tape index getdates() { OLDIFS=$IFS IFS=$'\n' clipct=1 for i in $(grep \"d $tmpfn); do dt=${i//\"dcrv-} dt=${dt//_*} [[ $clipct -eq 1 ]] && first_dt=$(fixdfmt $dt) ((clipct++)) done last_dt=$(fixdfmt $dt) IFS=$OLDIFS }
## download video with output to tmpfn & rewind tape when done echo -e "\nCapture Started: $(date '+%b %e %T')\n" | tee -a $tmpfn
date '+\nCapture Started: %b %e %T\n' | tee -a $tmpfn
dvgrab -rewind -timestamp -autosplit=3600 -format raw dcrv- 2>&1 | tee -a $tmpfn dvcont rewind
## fix the \r issue cat $tmpfn | sed 's/^[[:space:]]*\r//' > /tmp/fix.log cp /tmp/fix.log $tmpfn
You could combine that with the grep. Do you get those \r on the same lines as the '"dcrv-'? Alternatively: sed -i 's/^[[:space:]]*\r//' $tmpfn HTH, -dnh -- If you don't see why, please stay the fuck away from my code. -- Paul "Rusty" Russel, in /usr/src/linux/Documentation/DocBook/kernel-locking.tmpl -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org