64 lines
1.3 KiB
Bash
64 lines
1.3 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
|
|
if kill -0 ${child} >/dev/null 2>&1; then
|
|
activeChildren="${activeChildren} ${child}"
|
|
fi
|
|
done
|
|
|
|
# if no active children, trim the whitespace so we can check for empty string
|
|
|
|
activeChildren=$(echo ${activeChildren} | xargs echo)
|
|
if [ -z "${activeChildren}" ]; then
|
|
break
|
|
else
|
|
activeChildren=""
|
|
fi
|
|
sleep 5
|
|
done
|
|
|
|
echo "Everything is OK! Press Enter to finish."
|
|
read weAreDone
|