3 Bash
Caffeine Fueled edited this page 2025-12-18 16:52:44 +00:00

Running multiple commands at once

{ cmd() { printf "\n# %s\n" "$*"; "$@"; }; \
    cmd dig MX example.com +short; \
    cmd dig TXT example.com +short; \
    cmd dig TXT _dmarc.example.com +short; \
    cmd dig TXT *._domainkey.example.com +short; \
    } 2>&1

Looping through commands with list of items

while read ip; do
  sudo ufw allow in on eth0 from $ip to 192.0.2.0/24 port 80 proto tcp
  sudo ufw allow in on eth0 from $ip to 192.0.2.0/24 port 443 proto tcp
done < whitelist.txt

#!/bin/bash

while read domain; do
    echo "$domain"
    dig MX $domain +short
    dig TXT $domain +short
    dig TXT _dmarc.$domain +short
    dig TXT *._domainkey.$domain +short
    echo ""
done < domain-list.txt

Show counter for unique lines

sort file.txt | uniq -c | sort -nr

Curl - Simple API call

curl -X POST http://localhost:8000/api/run1/ \
  -H "Authorization: Bearer 9d207bf0-10f5-4d8f-a479-22ff5aeff8d1" \
  -d "host_a,is ok"

Another List

  • find / -type f -name “inventory.ini” 2>/dev/null
  • for file in *.md; do mv "$file" "prefix_$file"; done
  • python3 -m http.server 9100 --bind 10.20.30.57 --directory /path/to/directory
  • find . -maxdepth 1 -type f | wc -l
  • grep -rl "SSL-VPN is disabled" . --include="*.logs" | wc -l
  • find . -type f -exec grep -l 'SSL-VPN is disabled' {} + | wc -l
  • find . -type f -exec grep -lZ 'SSL-VPN is disabled' {} + | xargs -0 rm -f
  • find . -maxdepth 1 -type f -exec head -n -10 {} \;
  • find . -type f -exec cat -- {} + | less