I have a script to check a file sequence for missing frames. It used to work in true Unix but now on OSX 10.6.4 (bash) it reports every frame is missing. Hopefully someone here can help.
#!/bin/csh -f
if ($#argv < 1) then
echo
echo "Usage: checkseq <name> "
echo
exit -1
endif
@ max = 0
@ min = 999999
foreach i ( `\ls ./$1*.dpx` )
set nohead = $i:t
set no_dpx_ext = $nohead:r
@ current_count = $no_dpx_ext:e
if ($max < $current_count) then
@ max = $current_count
endif
if ($min > $current_count) then
@ min = $current_count
endif
end
@ count = $min
loop:
if (!(-e $1.$count.dpx)) then
echo "File $1.$count.dpx ALERT IMAGE MISSING"
endif
@ count++
if ($count > $max) then
echo ""
echo ""
echo " First image in sequence: $min"
echo " Last image in sequence: $max"
echo ""
echo " Unless specified, all images "
echo " between $min and $max are present."
echo ""
exit 1
else
goto loop
endif
---------- Post updated at 09:32 AM ---------- Previous update was at 09:30 AM ----------
Oh yeah, one more thing the file sequences are named like this:
"BT_103_v23.00139.dpx"
You're certainly not running it in bash, not sure why you mention it at all.
I see nothing in that code which would have ever added leading zeroes to your strings.
There's plenty of things in your script which in a bourne shell would be "useless use of ls *" and the like but in csh these constructs may actually be necessary...
But whether your shell be csh or zsh or whatever you can't exit -1, that value's nonsensical. It has to be a positive value between 0-255 inclusive.
Most of us aren't too fluent in CSH for a variety of reasons which cts already linked. You'd do better to learn a real scripting language. Trying a solution in bash for you.
I surmise that the version of csh you used to use had these :r etc string operations. Mine certainly doesn't and may be what broke down when you brought this script over.
---------- Post updated at 10:42 AM ---------- Previous update was at 09:49 AM ----------
#!/bin/bash
MAX=0 MIN=999999 TOTAL=0
# Don't have functions in csh. Can't redirect to stderr properly either.
function die # Print an error message to stderr, return 1
{
echo "$@" >&2 ; exit 1
}
[ "$#" -ne 1 ] && die "Usage: $0 <prefix>" # Die unless exactly 1 arg
# Loop over all files. (NOTE: May exceed argmax in other shells)
for I in ${1}.[0-9][0-9][0-9][0-9][0-9].dpx
do
[ -f "$I" ] || die "No files found for prefix $1"
# csh doesn't have a proper 'read'. You can read from your TTY, that's it
IFS="." read G C G <<< "$I" # Extract number from string
# Strip all leading zeroes
while [ "${C:0:1}" == "0" ] && [ ! -z "${C:1:1}" ]
do
C="${C##0}"
done
[ "$C" -gt "$MAX" ] && MAX=$C # Update max
[ "$C" -lt "$MIN" ] && MIN=$C # Update min
((TOTAL++))
done
for ((N=MIN; N<=MAX; N++))
do
FILE=$(printf "%s.%05d.%s" "$1" $N "dpx")
[ -f "$FILE" ] || echo "$FILE missing" >&2
done
[ "$TOTAL" -lt "$(((MAX-MIN)+1))" ] &&
die "$((((MAX-MIN-TOTAL)+1))) files missing"
printf "No files missing in %s.%05d.dpx - %s.%05d.dpx\n" $1 $MIN $1 $MAX >&2
exit 0