Bash scripts to help clean up a LastPass vault
⚠️ Warning: Theses scripts remove items from a LastPass vault! Use with cation!
brew install lastpass-cli jq whois
chmod +x check-urls.sh rm-dead-url-items.sh
./check-urls.sh dead-urls.csv
./rm-dead-url-items.sh dead-urls.csv
rm dead-urls.csvI have been using LastPass as my password manager for quite some time and now have over 1,000 items. I have realized that a lot of my items haven't been used in quite some time and so I wanted to clean it up. Going through all of the entries manually is a daunting task and so I decided to leverage lastpass-cli to automate the cleanup.
One cleanup task is to remove items to websites that no longer exist.
One way of doing this is to check if the url parameter is actually a dead url.
Sometime the sub domain isn't available anymore but the website still exists.
Another cleanup task is to rename the items. Since I am using the command line client more, I decided to replace spaces with dashes and convert the names to lowercase to make it easier to work with the command prompt.
brew install lastpass-cli jq whois
# or
task deps
# or
brew install $(cat formulas)| Script | Description |
|---|---|
check-urls.sh |
Check LastPass vault for dead urls |
rm-dead-url-items.sh |
Remove items with dead urls from LastPass vault |
check-names.sh |
Check LastPass vault for items that need to be renamed |
rename-items.sh |
Rename items from LastPass vault |
check-urls.sh checks each item for the following:
- Skips the item if no URL is set or is equal to
ns - Checks if the main domain exists with
whois. It does not check the sub domain. It also does not handle urls with more than one suffix (such asco.uk).
check-names.sh renames the files with the following changes:
- Remove
.com,.gov,.net - Replace spaces with dashes
- Remove trailing and leader white space
- Remove apostrophes
- Convert to lowercase
check-names.sh - groups can be ignred by changing the IGNORE_GROUPS array in the header of the file.
Be sure to put the names in double quotes with no commas in between
...
IGNORE_GROUPS=("Shared-Us" "Secure Notes")
...Be sure to backup the vault before using these scripts.
lpass export > backup.csv
# or
task backupMake the scripts executable
chmod +x check-urls.sh rm-dead-url-items.sh check-names.sh rename-items.shCheck items for dead urls and export them to a csv file
./check-urls.sh dead-urls.csv
# or
task urlsManually review the csv file to confirm that there aren't any items that should not be deleted.
Remove the items with dead urls.
./rm-dead-url-items.sh dead-urls.csv
# or
task rmRemove the dead url csv file.
rm dead-urls.csvRename items and export them to a csv file
./check-names.sh rename.csv
# or
task namesManually review the csv file to confirm that there aren't any items that should not be renamed.
Rename items that need to be renamed.
./rename-items.sh rename.csv
# or
task renameRemove the rename csv file.
rm rename.csvThis repository uses go-task to automate tasks.
⚠️ Warning:task cleanremoves allcsvfiles includingbackup.csv
# Print a list of tasks
taskThis project was started in 2022 by Nicholas Wilde.