This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| bigip-f5:scripts:listing-unused-certificates-via-tmsh [2026/02/12 18:12] – admin | bigip-f5:scripts:listing-unused-certificates-via-tmsh [2026/02/12 18:13] (current) – removed admin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ==TAKE A BACKUP FIRST== | ||
| - | |||
| - | **Unused Certificates For Loop** | ||
| - | |||
| - | < | ||
| - | for cert in $(tmsh list sys file ssl-cert | grep "sys file ssl-cert" | ||
| - | if ! tmsh list ltm profile client-ssl | grep -q $cert; then | ||
| - | echo " | ||
| - | fi | ||
| - | done | ||
| - | |||
| - | {{output}} | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | Unused certificate: | ||
| - | </ | ||
| - | |||
| - | **Cool, lets take this further. let’s put each entry (take certificates loop) into an array so we can manipulate it later, in a deletion loop.** | ||
| - | |||
| - | < | ||
| - | # Declare an array to store unused certificates | ||
| - | unused_certs=() | ||
| - | |||
| - | # List of certificates to exclude (exclude these system certs) | ||
| - | exclude_list=(" | ||
| - | |||
| - | # Loop through each certificate found in BIG-IP | ||
| - | for cert in $(tmsh list sys file ssl-cert | grep "sys file ssl-cert" | ||
| - | # Skip certificates in the exclude list | ||
| - | if [[ " ${exclude_list[@]} " =~ " $cert " ]]; then | ||
| - | continue | ||
| - | fi | ||
| - | |||
| - | if ! tmsh list ltm profile client-ssl | grep -q $cert; then | ||
| - | unused_certs+=(" | ||
| - | fi | ||
| - | done | ||
| - | |||
| - | # Dry run: Print the certificates that would be deleted | ||
| - | echo "Dry Run: The following unused certificates would be deleted:" | ||
| - | for cert in " | ||
| - | echo " | ||
| - | done | ||
| - | |||
| - | {{output}} | ||
| - | test30.infotechguy.dev_2025_112491.crt | ||
| - | test30.infotechguy.dev_2025_140516.crt | ||
| - | test30.infotechguy.dev_2025_196380.crt | ||
| - | test30.infotechguy.dev_2025_827939.crt | ||
| - | test31.infotechguy.dev_2025_112491.crt | ||
| - | test31.infotechguy.dev_2025_140516.crt | ||
| - | test31.infotechguy.dev_2025_196380.crt | ||
| - | test31.infotechguy.dev_2025_827939.crt | ||
| - | test32.infotechguy.dev_2025_112491.crt | ||
| - | test32.infotechguy.dev_2025_140516.crt | ||
| - | test32.infotechguy.dev_2025_196380.crt | ||
| - | test32.infotechguy.dev_2025_827939.crt | ||
| - | </ | ||
| - | |||
| - | |||
| - | |||