Ever wondered how Linux professionals automate tasks so effortlessly?
The secret lies in Bash scripting — one of the most powerful skills you can learn as a beginner in Linux.
💡 What you’ll learn in this tutorial:
✔️ Basics of Linux command line
✔️ How to create and run your first shell script
✔️ Understanding variables, loops, and conditions
✔️ Automating daily repetitive tasks
✔️ Real-world examples to build confidence
🧠 Why Bash scripting?
Because it transforms you from someone who uses commands…
into someone who controls the system.
Whether you're stepping into IT, cybersecurity, or DevOps — this is your foundation.
⚡ No heavy theory. No confusion.
Just clear, practical learning for beginners.
👉 Start now and take your first step toward mastering Linux.
🛠️ Automated Nmap Scan Script (Beginner → Practical)
Final result will be on the same drive.
Now the script is below .
#!/bin/bash
# ==============================
# Nmap Automation Script
# ==============================
# Create output directory with timestamp
timestamp=$(date +"%Y-%m-%d_%H-%M-%S")
output_dir="nmap_scan_$timestamp"
mkdir -p "$output_dir"
echo "=============================="
echo " Nmap Automation Script Start "
echo "=============================="
# Ask user for target
echo "Enter target IP or subnet (e.g. 192.168.1.1 or 192.168.1.0/24):"
read target
# Ask scan type
echo "Select Scan Type:"
echo "1) Quick Scan"
echo "2) Full Port Scan"
echo "3) Stealth Scan"
read choice
# Define scan based on user choice
case $choice in
1)
scan_type="-T4 -F"
scan_name="quick_scan"
;;
2)
scan_type="-p- -T4"
scan_name="full_scan"
;;
3)
scan_type="-sS -T4"
scan_name="stealth_scan"
;;
*)
echo "Invalid choice. Exiting..."
exit 1
;;
esac
# Run Nmap scan
echo "Running Nmap scan on $target ..."
nmap $scan_type $target -oN "$output_dir/${scan_name}.txt" \
-oX "$output_dir/${scan_name}.xml" \
-oG "$output_dir/${scan_name}.gnmap"
# Check if scan was successful
if [ $? -eq 0 ]; then
echo "Scan completed successfully!"
else
echo "Scan failed!"
exit 1
fi
# Extract open ports
echo "Extracting open ports..."
grep "open" "$output_dir/${scan_name}.gnmap" > "$output_dir/open_ports.txt"
# Summary
echo "=============================="
echo " Scan Completed "
echo "Results saved in: $output_dir"
echo "Open ports saved in: open_ports.txt"
echo "=============================="
▶️ How to Use
chmod +x nmap_auto.sh
./nmap_auto.sh🧠 What This Script Actually Does (Important)
This is not just a script — it mimics real-world security workflow:
✔️ Creates timestamped scan folders
→ Like SOC evidence storage
✔️ Supports multiple scan types
→ Quick / Full / Stealth
✔️ Saves output in 3 formats
.txt→ human readable.xml→ for tools (ELK/Splunk integration).gnmap→ grep-friendly✔️ Extracts open ports automatically
→ Useful for alerting & correlation



Comments
Post a Comment