I have a workstation that we have set up to sanitize multiple hard drives. I run a script that detects the hard drives and then runs the 'shred' command on each one. The problem is, if any of the hard drives fail (where Ubuntu no longer sees the drive) while 'shred' is running, rather than halting, 'shred' will output into infinity with line after line of this:
shred: /dev/sdd: error writing at offset 103456287104: Input/Output error
I don't see any options for 'shred' to enable it to exit if it encounters errors, and I obviously don't want the script to just run forever with the I/O error. Since 'shred' won't halt on it's own when it encounters this error, something else would have be running in parallel to do some kind of error-checking. In my script, I have the verbose output of 'shred' redirected to a log file, and I actually use that log file to check for successful completion of 'shred' in another part of the script. But I'm not sure how to continuously check that log file while 'shred' is still running.
Anyone have any ideas for how I can accomplish this kind of "parallel error-checking?"
I know the 'wipe' command exits when it detects I/O errors, but for reasons beyond our control, we are limited to using 'shred'. It's kind of frustrating that 'shred' doesn't do the same. It would seem like a no-brainer to have it halt upon error, but.....it doesn't.
This is the "shredding" part of my script:
#!/bin/bash
log=/root/sanilog.txt
## get disks list
drives=$(lsblk -nodeps -n -o name |grep "sd")
for d in $drives; do
shred -n 3 -v /dev/$d >> $log 2>&1
done
tee, and when it detects errors stop the process? - Have you decided what to do with the drive, when you encounter errors (mark the bad sectors and try again with shred or some other software tool, or make the drive unreadable by physical means)? – sudodus Dec 12 '19 at 18:36&and have it check maybe every tenth second for the tail of the logfile, and if there is an error output, stop. Then start your script with shred. – sudodus Dec 12 '19 at 21:11