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:

  1. - touch → Create a file.
  2. - vim → Open and edit files (Esc + i to insert, :wq! to save).
  3. - cd folder_name → Navigate to a directory.
  4. - cat → Read a file without opening it.
  5. - ls → List files in a directory.
  6. - chmod → Modify file permissions.
  7. - man → Get detailed command documentation.
  8. - sh or ./ → Execute a shell script.
  9. - pwd → Display the current directory.
  10. - mkdir → Create a new directory.
  11. - ls -ltr → List files with timestamps.
  12. - cd .. → Move back to the previous directory.
  13. - mv old new → Rename a file or script.

✅ System Monitoring & Process Management:

  1. df → Check available storage.
  2. free → View memory usage.
  3. nproc → Find out the number of CPU cores.
  4. top → Monitor running processes.
  5. echo "text" → Print a message to the terminal.
  6. set -x → Enable debug mode to see commands with output.
  7. ps -ef → List all running processes.
  8. ps -ef | grep "amazon" → Filter a specific process.
  9. awk -F" " '{print $2}' → Extract column data from text.

✅ Piping & Filtering:

  1. command | grep "info" → Filter output based on a keyword.
  2. set -e → Exit the script if an error occurs.
  3. set -o pipefail → Ensure the last command in a pipeline runs successfully.

✅ Networking & APIs:

  1. curl → Fetch data from external sources.
  2. curl | grep error → Fetch logs and filter errors.
  3. wget → Download files and analyze them.

✅ User Management & File Search:

  1. find / -name pam.sd → Locate a file.
  2. sudo su - → Switch to root user.
  3. su username → Switch to a different user.

✅ Shell Scripting Fundamentals:

  1. if-else → Conditional execution.
  2. for → Loops for iteration.
  3. trap "echo don't use the ctrl+c" SIGINT → Prevent script termination on Ctrl+C.

✅ AWS + Shell Scripting:

  1. 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