LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help with a script to crc32 check if multiple files are corrupt or not (https://www.linuxquestions.org/questions/linux-newbie-8/help-with-a-script-to-crc32-check-if-multiple-files-are-corrupt-or-not-847988/)

vega2000 12-02-2010 01:46 PM

Help with a script to crc32 check if multiple files are corrupt or not
 
Hi,
I need help to write a script that scans a folder to see which files are corrupt and if they are move them to another folder.
All files have in it's filename CRC32 hash that I want to check if it's correct.

Something like this:
Code:

Filename: . . . . .filename S01.E01 [CRC32Sum].mkv
Should have CRC: . CRC32Sum
CRC is: . . . . . .muS23CRC
File is: . . . . . CORRUPT
. . . Moving it to: /path/to/folder/

Something like this:
Filename: . . . . .filename S01.E02 [CRC32Sum].mkv
Should have CRC: . CRC32Sum
CRC is: . . . . . .CRC32Sum
File is: . . . . . Okey.

Thanks for helping,
And sorry if it's a bit messy but a bit stressed out after recovering(hopefully) my full dvd collection from a failed drive. ;p

TB0ne 12-02-2010 02:11 PM

Quote:

Originally Posted by vega2000 (Post 4178627)
Hi,
I need help to write a script that scans a folder to see which files are corrupt and if they are move them to another folder.
All files have in it's filename CRC32 hash that I want to check if it's correct.

Something like this:
Code:

Filename: . . . . .filename S01.E01 [CRC32Sum].mkv
Should have CRC: . CRC32Sum
CRC is: . . . . . .muS23CRC
File is: . . . . . CORRUPT
. . . Moving it to: /path/to/folder/

Something like this:
Filename: . . . . .filename S01.E02 [CRC32Sum].mkv
Should have CRC: . CRC32Sum
CRC is: . . . . . .CRC32Sum
File is: . . . . . Okey.

Thanks for helping,
And sorry if it's a bit messy but a bit stressed out after recovering(hopefully) my full dvd collection from a failed drive. ;p

Ok...we'll be glad to HELP you, but we're not going to write it for you. Post what you've written/tried so far, along with some examples of your input data.

Otherwise, there are thousands of scripting tutorials you can easily find on Google, to help you get started.

vega2000 12-02-2010 03:09 PM

My idea is something like this:
Code:

find ./path/to/file | while read files
        do
        crcsum=`crc32 "$files"`
        if [ $crcsum == ???? ]
        then
                ...
        else
                ..
        fi
done

EDIT: hmm... have made something that seems to work will do some more testing tomorrow, if someone want to clean up it or have any more "correct" way of doing it please let me know. ;)

Code:

#!/bin/bash
find ./ | while read files
        do
        current_crc32=`crc32 "$files"`
        filename=`basename "${files}"`
        t=`echo ${filename##*[}`
        file_crc32=`echo ${t%]*}`

        echo "Filename:          $filename"
        echo "Should have CRC:    $file_crc32"
        echo "CRC is:            $current_crc32"
        if [[ $file_crc32 == $current_crc32 ]]
                then
                echo "File is:            Okey."
        else
                echo "File is:            CORRUPT!"
                mv "$files" ./corrupt/
        fi
done



All times are GMT -5. The time now is 11:55 PM.