Six essential scripts every L2 engineer writes and runs — from auto-restarting a failed service to scheduling health checks with cron. Every script is broken down line by line so you know exactly what each part does and when to use it.
Each script card gives you four things:
What it does — plain English explanation of the purpose.
Full script — the complete, runnable bash code you copy to Kali.
Line-by-line breakdown — what every part of the script means.
When to use it — the real L2 scenario where this script saves you time.
systemctl is-active --quiet checks if the service is running silently. If NOT running — go into the if block.fi closes the if block.Find all log lines for a specific TXN ID. The -B 3 flag shows 3 lines before each error — reveals the build-up.
-15 sends a clean stop signal. The process shuts down properly. -9 forces it immediately — never use on a DB process.
free -h shows the full picture. The awk commands extract just available RAM and swap used for scripting.
Ping tests basic connectivity. netstat counts open and stuck connections — TIME_WAIT above normal = connection leak.
-c create, -z gzip, -f filename, -t list, -x extract, -C destination. These 3 cover 100% of backup operations.
Checks the TLS certificate of a live server and shows notBefore and notAfter dates. Immediately tells you if a cert is expired or about to expire.
Mobile-first, center-aligned reference for L2 Bash scripts — optimized for iOS and Android screens while matching the site's colour and card style.
if ! systemctl is-active checks if a service is down and restarts it automatically — schedule every 5 minutes via crontabgrep -i error /var/log/app.log | wc -l counts errors and sort | uniq -c shows the breakdown by typedf -h | awk '$5 > 80 {print $0}' filters partitions above 80% — always run first in any investigationps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head shows top processes by CPU — then check etime to see how long they have been runningtar -czf logs.tar.gz /var/log/app compresses logs — timestamped backups with 7-day auto-cleanup prevent disk full incidents*/5 * * * * /home/ops/healthcheck.sh schedules any script to run automatically — the 5-field cron syntax controls when