59 lines
1.1 KiB
Bash
59 lines
1.1 KiB
Bash
|
#!/bin/sh
|
||
|
|
||
|
drives=$(ls /dev/sd[a-z] 2> /dev/null)
|
||
|
|
||
|
safeDrives=""
|
||
|
children=""
|
||
|
activeChildren=""
|
||
|
|
||
|
# safe drives are those which are not currently mounted
|
||
|
|
||
|
for x in ${drives}; do
|
||
|
mounted=$(df -h | grep ${x} | awk '{print $1}')
|
||
|
if [ -z "${mounted}" ]; then
|
||
|
safeDrives="${safeDrives} ${x}"
|
||
|
n=$((n + 1))
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
echo "Summary of currently mounted drives:"
|
||
|
df -h
|
||
|
echo ""
|
||
|
echo "verify that the following drives are all OK to wipe:"
|
||
|
echo "${safeDrives}"
|
||
|
echo ""
|
||
|
|
||
|
while [ "${isItSafe}" != "y" ]; do
|
||
|
echo "(y/n)"
|
||
|
read isItSafe
|
||
|
if [ "${isItSafe}" = "n" ]; then
|
||
|
exit
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
echo "OK, shredding!"
|
||
|
|
||
|
# fork each shred into the background and record its PID
|
||
|
|
||
|
for drive in ${safeDrives}; do
|
||
|
shred -n 1 -z -v ${drive} & children="${children} $!"
|
||
|
done
|
||
|
|
||
|
# check if the shred PIDs have completed;
|
||
|
# if so, everything is OK!
|
||
|
|
||
|
while true; do
|
||
|
for child in ${children}; do
|
||
|
activeChildren="${activeChildren} $(ps T | grep $child | awk '{print $1}')"
|
||
|
done
|
||
|
if [ -z "${activeChildren}" ]; then
|
||
|
break
|
||
|
else
|
||
|
activeChildren=""
|
||
|
fi
|
||
|
sleep 5
|
||
|
done
|
||
|
|
||
|
echo "Everything is OK! Press Enter to finish."
|
||
|
read weAreDone
|