Skip to content

Instantly share code, notes, and snippets.

@thewisenerd
Last active February 16, 2023 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thewisenerd/62994d616f2ac4a2a3aeb9f72a5470f9 to your computer and use it in GitHub Desktop.
Save thewisenerd/62994d616f2ac4a2a3aeb9f72a5470f9 to your computer and use it in GitHub Desktop.
#!/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)
@thewisenerd
Copy link
Author

cat badblocks-pipe-sdc.txt | rg -ao '\d{1,3}:\d{2}:\d{2} elapsed' | tail -n 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment