Last active
February 16, 2023 14:59
-
-
Save thewisenerd/62994d616f2ac4a2a3aeb9f72a5470f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# HAHA, so you may not blame me. | |
exit 1 | |
set -euo pipefail | |
# eg sda1 | |
DISK="$1" | |
LOCK_FILE="badblocks-lock-$DISK.txt" | |
OUTPUT_FILE="badblocks-output-$DISK.txt" | |
PIPE_FILE="badblocks-pipe-$DISK" | |
if [[ ! -e "/dev/$DISK" ]]; then | |
echo "/dev/$DISK does not exist" | |
exit 1 | |
fi | |
if [[ -e "$LOCK_FILE" ]]; then | |
echo "$LOCK_FILE exists, please check and remove before continuing" | |
exit 1 | |
fi | |
touch "badblocks-lock-$DISK.txt" | |
blocksize=4096 | |
testblocks=8192 | |
sudo badblocks -wsv -b "$blocksize" -c "$testblocks" -o "badblocks-output-$DISK.txt" "/dev/$DISK" > >(tee -a "badblocks-pipe-$DISK".txt) 2> >(tee -a "badblocks-pipe-$DISK".txt >&2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cat badblocks-pipe-sdc.txt | rg -ao '\d{1,3}:\d{2}:\d{2} elapsed' | tail -n 1