Skip to content

Instantly share code, notes, and snippets.

@jeenuv
Created November 26, 2014 16:57
Show Gist options
  • Select an option

  • Save jeenuv/467477473f36cf6ee596 to your computer and use it in GitHub Desktop.

Select an option

Save jeenuv/467477473f36cf6ee596 to your computer and use it in GitHub Desktop.
Find locked SQLite directories in a directory
#!/bin/bash
#
# Find SQLite data base in a directory and print those that were locked
#
find -type f -print0 |
xargs -0 file |
# Filter sqlite data base files
awk -F: -vIGNORECASE=1 '/sqlite/{printf "%s\0", $1}' |
xargs -0 sh -c '
f=$(mktemp)
for d; do
# sqlite3 does not have sensible exit code
# no matter what the outcome of this command is
sqlite3 "$d" ".dump" >"$f" 2>&1
# If the database was locked, the .dump will print a
# message with this content
grep -qF "database is locked *****" "$f" && echo "$d"
done' sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment