Created
November 26, 2014 16:57
-
-
Save jeenuv/467477473f36cf6ee596 to your computer and use it in GitHub Desktop.
Find locked SQLite directories in a directory
This file contains hidden or 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
| #!/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