-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecureErase.sh
More file actions
40 lines (33 loc) · 953 Bytes
/
SecureErase.sh
File metadata and controls
40 lines (33 loc) · 953 Bytes
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
#!/bin/bash
# Function to check device existence
check_device() {
if [ ! -e "$1" ]; then
echo "Device $1 does not exist."
return 1
fi
}
# Function to securely erase a device
secure_erase() {
echo "Erasing $1..."
dd if=/dev/urandom of="$1" bs=4M status=progress
echo "Finished erasing $1."
}
# Check if the script is run with superuser privileges
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root (sudo)."
exit 1
fi
# Prompt the user for the target devices
read -p "Enter the target devices (e.g., /dev/sdX /dev/sdY): " target_devices
# Iterate through the space-separated list of target devices
for device in $target_devices; do
# Check if the device exists
check_device "$device" || continue
# Avoid erasing important devices
if [ "$device" == "/dev/sda" ]; then
echo "Skipping erasure of the root device (/dev/sda)."
continue
fi
# Overwrite with random data
secure_erase "$device"
done