Important: most scripts are tested and have been used and modified over time. Nevertheless, use with caution and your own risk!

I might add a description to them, but nothing planned yet. For now, this is my scrapyard of commands and scripts. Take what you need, modify, delete, combine, etc.

Linux

Run 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

Reference with more examples

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

# Second Example
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

Simple for-loop #

for i in $(seq 1 101); do curl -s -o /dev/null -w "%{http_code}\n"
 http://localhost:8000/api/ip/8.8.8.8; done

Delete all files in current directory where the first lines contains term #

find . -type f -exec sh -c 'head -n1 "$1" | grep -q "SSL-VPN is disabled" && rm -f "$1"' _ {} \;

Searching, sorting, counting #

# count files in dir
find . -maxdepth 1 -type f | wc -l

# get line count of each file in directory
for f in *; do     wc -l "$f"  ; done | sort -h

# show counter for unique lines
sort file.txt | uniq -c | sort -nr

# Too lazy to write those out for now
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

Save remote certificate to file #

openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 2>/dev/null \
| openssl x509 -outform PEM > remote-cert.pem

Podman #


# Container healthcheck
podman run -d --name web \
  --health-cmd='curl "http://192.168.250.250:3001/api/push/FHahMOAw7p?status=up&msg=OK&ping=" || exit 1' \
  --health-interval=60s \
  --health-timeout=3s \
  --health-retries=3 \
  nginx:alpine


# Limiting resources
    --cpus=0.3 \
    --memory=2g \
    --memory-swap=2.5g \
    --cpu-shares=512 \

# Hardening
    --read-only \
    --security-opt no-new-privileges \
    --cap-drop ALL \
    --cap-add=CHOWN \
    --cap-add=NET_BIND_SERVICE \
    --cap-add=SETGID \
    --cap-add=SETUID \

    --tmpfs /tmp:rw,size=256m \

# User ID / Quadlet
UserNS=keep-id:uid=1000,gid=1000
User=1000
Group=1000 

Curl #

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

SSH #

# for automated run
-o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no"

# keep alive for longer sessions
-o ServerAliveInterval=60 -o ServerAliveCountMax=3

Lingering #

loginctl show-user "$USER" -p Linger

sudo loginctl enable-linger USERNAME

Grep #

# default
grep -Iris SEARCHTERM .

# exclude
--exclude-dir=venv


Windows

Powershell #

Run command every n seconds #

Like watch -n 3 cmd on linux.

while($true){Invoke-WebRequest "http://192.168.18.6:8081/api/push/vmXn4K7PYl?status=up&msg=OK&ping=" -UseBasicParsing | Out-Null; Start-Sleep 60}

Simple API call #

$hostname = $env:COMPUTERNAME
$status = "OK"
$body = "$hostname,$status"

$headers = @{
    "Authorization" = "Bearer 9d207bf0-10f5-4d8f-a479-22ff5aeff8d1"
}

$domain = "http://example.com:8000/api/test1/"

Invoke-RestMethod -Uri $domain -Method Post -Body $body -Headers $headers