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
Top comments (0)