Skip to content

Instantly share code, notes, and snippets.

@r0t0shell
Created August 13, 2025 14:36
Show Gist options
  • Select an option

  • Save r0t0shell/8665f446d926b70815a218ff33528403 to your computer and use it in GitHub Desktop.

Select an option

Save r0t0shell/8665f446d926b70815a218ff33528403 to your computer and use it in GitHub Desktop.
Fish script to permanently delete Splunk buckets older than 372 days.
#!/usr/bin/fish
set OLDER_THAN (date --date="372 days ago" +%s)
set mode $argv[1]
set folders $argv[2..-1]
if test (count $folders) -eq 0
echo "Err: no folders".
echo "Usage: $0 [delete|dryrun] <folder1> [folder2 ...]"
exit 1
end
if test "$mode" = "delete"
echo "You have chosen death! For old buckets that is..."
echo
end
find $folders -maxdepth 3 -type d -name "db_*" | while read bucket
set current (date +%s)
set basename (basename "$bucket")
set latest (echo "$basename" | cut -d'_' -f3)
set difference (math --scale=0 $current - $latest)
if [ "$latest" -lt $OLDER_THAN ]
echo -n "$bucket" (math --scale=0 $difference / 86400 )'d' (date -d "@$latest")
if test "$mode" = "delete"
rm -rf $bucket
echo -n "...sent to hell"
end
echo
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment