all repos — shredmaster @ 32943a97baeecbd1edfcf713f1511153b182fae7

script for wiping a bunch of drives at once

shredder.sh (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/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 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