LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-02-2010, 02:46 PM   #1
vega2000
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Rep: Reputation: 0
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
 
Old 12-02-2010, 03:11 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,331

Rep: Reputation: 3881Reputation: 3881Reputation: 3881Reputation: 3881Reputation: 3881Reputation: 3881Reputation: 3881Reputation: 3881Reputation: 3881Reputation: 3881Reputation: 3881
Quote:
Originally Posted by vega2000 View Post
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.
 
Old 12-02-2010, 04:09 PM   #3
vega2000
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Original Poster
Rep: Reputation: 0
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

Last edited by vega2000; 12-02-2010 at 08:18 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
selectively check in multiple files using SVN sneakyimp Linux - Software 2 01-12-2010 05:19 PM
Creating a script to move or copy files into multiple directories below the files matthes138 Linux - Newbie 5 08-25-2009 05:57 PM
Script to check for and replace files? mac-mark Programming 2 03-22-2009 07:26 AM
bash script to check how many files in directory guest Programming 8 02-01-2009 12:55 AM
help with script to check processes on multiple servers ncsuapex Programming 7 06-10-2008 12:02 PM


All times are GMT -5. The time now is 01:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration