Wednesday 21 October 2009

Copy files to /dev/null

I have a suspected hard disk problem. What happens is when I do a large amount of disk reading (as in performing a backup) somewhere along the line the system freezes and needs to be reset. System logs show nothing useful.

So, what I want to do is basically read a whole bunch of files and directories and see if the failure occurs on a specific file (or files)

This is the first command I used;
find . -type f -print -exec sh -c 'cat "$1" >/dev/null' {} {} \; > readtest&

Basically it does a find for all files and then does a 'cat' of each file to /dev/null and finally appends the console output for that action to a file called "readtest".

The idea was that if it fails on a file I should be able to consult the "readtest" file which will tell me the last file which successfully copied.

You can watch the console output 'live' by using the tail command
tail -f readtest


The problem was that the 'find' command doesn't find files in alphabetical order so it is difficult to identify what the next file it was copying would be, so I modified my procedure.

First I created a small shell script called 'testfile'
#!/bin/sh
echo "Testing $1"
cat "$1" >/dev/null

Made it executable with
chmod +x testfile

then reran a slightly modified version of the above command;
find . -type f -print -exec sh -c './testfile "$1"' {} {} \; > readtest&

This will printout the file it is about to test beforehand so that if the system locks up during the reading of a file, I can consult the readtest log to see which file it was reading.

No comments: