Shell Scripting Bootcamp
(Beginner → Advanced)
MODULE 1 — INTRODUCTION TO SHELL SCRIPTING
Lesson 1: What Is Shell? What Is Bash?
A shell is a command interpreter in Linux. Bash is the most widely used.
#!/bin/bash echo "Hello World!"
Lesson 2: Variables
name="Ved" echo "Hello $name"
Lesson 3: User Input
read -p "Enter city: " city echo "You are from $city"
Lesson 4: Conditions
ping -c 1 google.com &> /dev/null if [ $? -eq 0 ]; then echo "Internet OK" else echo "No Internet" fi
Lesson 5: File Checks
if [ -f /etc/passwd ]; then echo "File exists" fi
MODULE 2 — INTERMEDIATE AUTOMATION
Lesson 6: Loops
services=("nginx" "sshd")
for s in "${services[@]}"; do
systemctl restart $s
done
Lesson 7: Log Analysis
grep "Failed password" /var/log/auth.log | awk '{print $11}' | uniq -c
Lesson 8: Backup Automation
src="/home/ved/docs" dest="/backup/docs_$(date +%F).tar.gz" tar -czf $dest $src
Lesson 9: Cron Jobs
0 2 * * * /scripts/backup.sh
Lesson 10: Menu Driven Tools
echo "1) Disk" echo "2) Memory" read choice case $choice in 1) df -h ;; 2) free -h ;; esac
MODULE 3 — ADVANCED SHELL SCRIPTING
Lesson 11: Functions
check_service() {
systemctl is-active $1
}
check_service nginx
Lesson 12: Error Handling
set -euo pipefail trap 'echo "Error at line $LINENO"' ERR
Lesson 13: Debugging
bash -x script.sh
Lesson 14: Arrays
servers=("node1" "node2")
for s in "${servers[@]}"; do
ssh $s uptime
done
Lesson 15: JSON Parsing (DevOps)
curl -s https://api.github.com/users/ved | jq '.public_repos'
Lesson 16: Kubernetes Automation
kubectl get pods -A | grep "$1"
Lesson 17: Parallel Execution
parallel -j 5 ping -c 1 ::: server1 server2 server3
Lesson 18: Logging
log=/var/log/myscript.log echo "$(date) - Started" >> $log
Lesson 19: Email Alerts
echo "Disk Alert" | mail -s "Warning" admin@example.com
MODULE 4 — REAL‑WORLD PROJECTS
Project 1: Server Health Dashboard
- CPU usage
- Memory
- Disk
- Top processes
Project 2: Log Analyzer
- Detect failed logins
- Detect suspicious IPs
- 500 error detection
- Export to CSV
Project 3: CI/CD Deployment Script
- Build Docker
- Push to registry
- Restart Kubernetes deployment
Project 4: Cloud Server Setup Script
- User creation
- SSH key automation
- Firewall setup
- Package installation
Project 5: Backup + Restore Automation
- Daily backup
- Encryption
- Upload to AWS S3
- Restore function
MODULE 5 — CHEAT SHEETS
Conditions
[ -f file ] [ -d dir ] [ -n "$x" ] [ $a -eq $b ]
Loops
for i in {1..10}; do
for f in *.log; do
Useful Tools
- awk
- sed
- grep
- curl
- jq
End of Bootcamp
Export this page as a PDF to save your full Shell Scripting Bootcamp.
