Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions delete-old-nodes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Delete Old Nodes
This will clean out nodes which have not been seen longer than the value of `$oldenough` - I've set this to one month.

I keep my api key in ~/keys/tailnetname.api.key - if you have them elsewhere, you should change the `$apikey` value.

And set `$tailnet` to the domain of your tailnet.
16 changes: 16 additions & 0 deletions delete-old-nodes/delete-old-nodes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

tailnet="tailnetname.com"
apikey=$(<$HOME/keys/${tailnet}.api.key)
oldenough=$(date -I --date="1 month ago")

curl -s "https://api.tailscale.com/api/v2/tailnet/$tailnet/devices" -u "$apikey:" |jq -r '.devices[] | "\(.lastSeen) \(.id)"' |
while read seen id; do
if [[ $seen < $oldenough ]]
then
echo $id " was last seen " $seen " getting rid of it"
curl -s -X DELETE "https://api.tailscale.com/api/v2/device/$id" -u "$apikey:"
else
echo $id " was last seen " $seen " keeping it"
fi
done