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; } cd /dat_e/dv/new || { echo "cannot change into /dat_e/dv/new, exiting..."; exit 2; } ## 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 } ## 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 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 ## get tape begin and end dates getdates ## write tape No. and begin & end dates to append file echo -e "\nTape: $tapect -- $first_dt - $last_dt\n" >> $tmpapp ## write dir content and capture info to append file and append to tape index, update capture log ls -l >> $tmpapp cat $tmpfn >> $tmpapp cat $tmpapp >>/dat_e/dv/tape-idx.txt cat $tmpfn >> /dat_e/dv/capture.log ## move dv clips to permanent dir and mirror on /dat_f mv /dat_e/dv/new/* /dat_e/dv/sony cp -uav /dat_e/dv/{sony,tape-idx.txt} /dat_f/dv/ ## update tape counter tapenext=$tapect ((tapenext+=1)) echo $tapenext >/dat_e/dv/tapect.txt echo " Tape count updated to: $tapenext" exit 0 -- David C. Rankin, J.D.,P.E. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org