Check file sequence script not working. Need help.

 
Thread Tools Search this Thread
Operating Systems OS X (Apple) Check file sequence script not working. Need help.
# 1  
Old 03-31-2011
Check file sequence script not working. Need help.

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.
Code:
#!/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"

Last edited by Scott; 03-31-2011 at 02:43 PM.. Reason: Please use code tags for code, not quote tags - and that's C-Shell, not Bash :)
# 2  
Old 04-01-2011
# 3  
Old 04-22-2011
No geeks left?

Is there anyone left who can fix this script? Oh, what sad times are these ...
# 4  
Old 04-25-2011
You agreed not to bump posts when you registered.

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 ----------

Code:
#!/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


Last edited by Corona688; 04-25-2011 at 05:28 PM.. Reason: Moved TOTAL++ to simplify code
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check the missing file based on sequence number.

Hi All, I have a requirement that i need to list only the missing sequences with a unix script. For Example: Input: FILE_001.txt FILE_002.txt FILE_005.txt FILE_006.txt FILE_008.txt FILE_009.txt FILE_010.txt FILE_014.txt Output: FILE_003.txt FILE_004.txt FILE_007.txt FILE_011.txt... (5 Replies)
Discussion started by: Arun1992
5 Replies

2. Shell Programming and Scripting

Shell script check syntax not working ...

Hello i have question that i want check syntax from my script shell with sh -n filename but it's not show something even i have wrong syntax in my file. why can this happened or any other way to check it? i use on header of file : #!/bin/sh thx before :) (7 Replies)
Discussion started by: Gochengz
7 Replies

3. Solaris

Escape Sequence for Capital Letters Input at Shell Not Working

Hello, I am running Solaris 8. When issuing the command "stty lcase" all text which is output to the terminal are capitalized. Letters that are supposed to be capitals are preceded by a backslash during output. All text which is input is converted to lower case. This is the expected behaviour... (5 Replies)
Discussion started by: rstor
5 Replies

4. Shell Programming and Scripting

How to check missing sequence?

I want to listed files every hours and check the missing sequence my file format is CV.020220131430.txt CV.020220131440.txt CV.020220131450.txt CV.ddmmyyhhm.txt how to check if i have missing files in sequence .. thanks (3 Replies)
Discussion started by: before4
3 Replies

5. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

6. Shell Programming and Scripting

Check Sequence

* Expiry DATE: * Address1: Address2: Address3: Address4: Address5: * PO_ref_number: aadad HolderId_1: HolderId_2: HolderId_3: HolderId_4: * adad: 00000 ada: 00000 adad: RANDOM adad: RANDOM ****************************** (4 Replies)
Discussion started by: arunshankar.c
4 Replies

7. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

8. Shell Programming and Scripting

Script to check file sequence

Hi everyone, I need help in creating a script that would check if the file sequence is in order in a particular directory. These are log files that are generated throughout the day. Example of the file name will be, ABC01_YYMMDDHHMM###### (ABC01_0904161829000001) Sometimes the file... (4 Replies)
Discussion started by: kumaran21
4 Replies

9. Shell Programming and Scripting

help - script can check jump sequence?

Hi, if I have a lot of files like (AABBCC0010, AABBCC0011, AABBCC0012....AABBCC1000), can I write a small script to check any sequence number jump and show me the result which sequence number? #The first sequence may start from 0010 or 0101... :confused: Thank you!! (10 Replies)
Discussion started by: happyv
10 Replies

10. UNIX for Dummies Questions & Answers

Script to check for a file, check for 2hrs. then quit

I wish to seach a Dir for a specific file, once the file is found i will perform additional logic. If the file is not found within two hours, i would like to exit. Logically, I'm looking for the best way to approach this Thanks for any assistance in advance. Note: I'm using a C shell and... (2 Replies)
Discussion started by: mmarsh
2 Replies
Login or Register to Ask a Question