Skip to content

Instantly share code, notes, and snippets.

@rdmarsh
Last active July 17, 2016 07:59
Show Gist options
  • Save rdmarsh/2c049a40c161d236272474186f21fdc8 to your computer and use it in GitHub Desktop.
Save rdmarsh/2c049a40c161d236272474186f21fdc8 to your computer and use it in GitHub Desktop.
autoshred disks inserted

Will automatically shred any inserted disks without warning.

Designed for raspberry pi.

sudo cp 91-shred_usb_device_rule.rules /etc/udev/rules.d/
sudo chmod 644 /etc/udev/rules.d/91-shred_usb_device_rule.rules
sudo cp shred_usb_device.sh /usr/local/bin/shred_usb_device.sh
sudo chmod 755 /usr/local/bin/shred_usb_device.sh
#place this file in /etc/udev/rules.d/91-shred_usb_device_rule.rules
#chmod 644 /etc/udev/rules.d/91-shred_usb_device_rule.rules
ACTION=="add", KERNEL=="sd?", RUN+="/usr/local/bin/shred_usb_device.sh /dev/$kernel"
#ACTION=="add", KERNEL=="sd?", RUN+="/usr/bin/shred -v /dev/$kernel 1>/dev/console 2>&1"
#!/bin/bash
#place this file in /usr/local/bin/shred_usb_device.sh
#chmod 755 /usr/local/bin/shred_usb_device.sh
set -euo pipefail
IFS=$'\n\t'
trap 'cat /etc/issue > /dev/console 2>&1 ; exit' 1 2 3 15
echo > /dev/console 2>&1
echo "starting shred of $1" > /dev/console 2>&1
echo > /dev/console 2>&1
/usr/bin/shred -fvz -n1 $1 > /dev/console 2>&1
echo > /dev/console 2>&1
echo "finished shred of $1" > /dev/console 2>&1
echo > /dev/console 2>&1
cat /etc/issue > /dev/console 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment