This week, I deep-dived into Shell Scripting for DevOps, exploring how to automate repetitive tasks, manage cloud resources, and interact with APIs using Linux commands. Learning these fundamentals has given me a better understanding of how scripting enhances efficiency in DevOps workflows. 💻⚡
🔍 Key Takeaways (Commands & Their Purpose)
✅ File Management & Navigation:
- - touch → Create a file.
- - vim → Open and edit files (Esc + i to insert, :wq! to save).
- - cd folder_name → Navigate to a directory.
- - cat → Read a file without opening it.
- - ls → List files in a directory.
- - chmod → Modify file permissions.
- - man → Get detailed command documentation.
- - sh or ./ → Execute a shell script.
- - pwd → Display the current directory.
- - mkdir → Create a new directory.
- - ls -ltr → List files with timestamps.
- - cd .. → Move back to the previous directory.
- - mv old new → Rename a file or script.
✅ System Monitoring & Process Management:
- df → Check available storage.
- free → View memory usage.
- nproc → Find out the number of CPU cores.
- top → Monitor running processes.
- echo "text" → Print a message to the terminal.
- set -x → Enable debug mode to see commands with output.
- ps -ef → List all running processes.
- ps -ef | grep "amazon" → Filter a specific process.
- awk -F" " '{print $2}' → Extract column data from text.
✅ Piping & Filtering:
- command | grep "info" → Filter output based on a keyword.
- set -e → Exit the script if an error occurs.
- set -o pipefail → Ensure the last command in a pipeline runs successfully.
✅ Networking & APIs:
- curl → Fetch data from external sources.
- curl | grep error → Fetch logs and filter errors.
- wget → Download files and analyze them.
✅ User Management & File Search:
- find / -name pam.sd → Locate a file.
- sudo su - → Switch to root user.
- su username → Switch to a different user.
✅ Shell Scripting Fundamentals:
- if-else → Conditional execution.
- for → Loops for iteration.
- trap "echo don't use the ctrl+c" SIGINT → Prevent script termination on Ctrl+C.
✅ AWS + Shell Scripting:
- aws s3 ls → List objects in an S3 bucket.
⚡ Challenges & Fixes
🔹 Issue 1: Permission Errors in Shell Scripts
Problem: Running ./script.sh resulted in a "Permission Denied" error.
Solution: Used chmod +x script.sh to make it executable.
🔹 Issue 2: AWS CLI Output Parsing
Problem: AWS CLI JSON output was difficult to read.
Solution: Used jq for better formatting:
Command - shCopyEditaws ec2 describe-instances | jq '.'
🚀 Next Steps: Diving deeper into advanced scripting, Git, and GitHub automation!
📌 Follow my journey on:
🔹 LinkedIn: https://www.linkedin.com/in/princemalikk
🔹 Dev.to: https://dev.to/princemalikk
🔹 GitHub: https://github.com/Princemalikk
🔹 Hashnode: https://princemalikk.hashnode.dev