Week 2: My Shell Scripting Journey ๐


As I continue my DevOps learning path, week 2 focused on mastering Shell Scripting, a powerful tool in automating tasks and managing system operations. Followed an excellent tutorial by TrainWithShubham: ๐ฅ Shell Scripting in One Shot | 3 Live Projects For DevOps (Hindi). From variables to cronjobs, Iโve encountered new challenges, but also discovered ways to solve them, all while creating a solid foundation for the upcoming weeks.
๐ Topics I Learned
During this week, I dived into the following topics:
Variables
I learned how to define and manipulate variables within Bash scripts.Arguments
Handling user inputs and positional parameters using command-line arguments.Conditionals
I explored how to control the flow of execution with if, else, and elif conditions.Loops
Implemented different types of loops:for
,while
, anduntil
loops to automate repetitive tasks.Functions
I structured my scripts better by creating reusable functions.Error Handling
Understanding how to handle errors effectively by checking command success and failure.AWS CLI
I integrated basic AWS CLI commands into my scripts for cloud automation.Makefiles
Automated build and execution tasks with Makefiles, making scripts more modular and maintainable.Backup
I created scripts for systematically backing up files and directories.Rotation
Managed storage space effectively by implementing backup rotation in my scripts.Cronjobs
Set up and configured cronjobs to schedule automatic execution of tasks.
๐ Challenges I Faced
1. Learning Shell Scripting and Makefile Syntax
At first, I found the syntax of Shell scripting and Makefiles quite overwhelming, especially with the different conventions and structures.
2. Setting Up Cronjobs
Another challenge I faced was configuring cronjobs correctly. I had difficulty ensuring the scripts ran at the specified times.
3. Pre-made Projects in Tutorials
The tutorials I followed used pre-made projects, which made it hard to connect the individual concepts I was learning with practical, standalone examples.
โ How I Solved These Challenges
1. Continuous Practice
Wrote dozens of tiny scripts and Makefiles, ran bash -n
and make -n
for syntax checks, and gradually internalized the differences between tabs/spaces and quoting rules.
2. Debugging Cronjobs
Added cd /full/path
at the start of each script, replaced bare commands with their absolute paths (e.g., /usr/bin/zip
), and redirected logs (>>/var/log/backup.log 2>&1
).
Added echo "DEBUG: reached backup step"
statements and then verified execution via grep CRON /var/log/syslog
.
3. Starting with Simpler Scripts
Rather than trying to dive into pre-built projects, I took the approach of writing simpler scripts to understand each topic individually. Iโll integrate these simpler scripts into larger projects as I go.
๐ Repository
You can find all the scripts and files I wrote during this week in my GitHub repository:
๐ My Shell Scripting Journey โ GitHub
Feel free to check them out, provide feedback, or suggest improvements! Iโd love to hear your thoughts.
This week was full of both challenges and breakthroughs. Shell scripting has already proven to be an essential tool in my DevOps toolkit, and Iโm looking forward to diving deeper in the coming weeks. Stay tuned for more updates on my journey! ๐
Subscribe to my newsletter
Read articles from Pranab Nandi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
