Day 5 : Advanced shell scripting

Day 5 : Advanced shell scripting

Hello, DevOps enthusiasts! Today, I took my Linux skills a step further with advanced shell scripting and explored user management. Here's a quick breakdown of what I learned and accomplished on Day 5 of my #90DaysOfDevOps challenge:

Creating 90 Directories in Seconds! 😲

Imagine manually creating 90 directories one by one – that would take forever! But with a simple shell command, I created 90 directories in a matter of seconds:

This command created directories named day1, day2, all the way up to day90. Simple and efficient!

🛠️ Tasks for Today:

1. Write a Bash Script to Create Multiple Directories

I wrote a shell script, createDirectories.sh, that takes three arguments (directory name, start number, and end number) and dynamically creates a specified number of directories.

Here’s the script:

Now you want to delete Multiple directory in a one shot 👍

2. Automate Backups with a Script

One essential task for DevOps is taking backups. I created a simple backup script that copies all my files into a backup directory:

This script uses rsync to sync files from the source to the backup location, ensuring my work is safe. To automate it, I’ll set up a cron job!

3. Set Up Cron Jobs for Automated Backups

I learned about cron and crontab, which allow us to schedule tasks in Linux. For example, to schedule my backup script to run every day, I would add this line to my crontab:

This ensures my files are backed up daily without me having to remember to do it manually!

4. User Management

User management is key in Linux. Each user is unique and assigned a specific ID. I created two users using the following commands :

To display the usernames:

🎯 Final Thoughts

Today’s tasks helped me understand the power of automation through shell scripting, backups, and user management. These skills are super important for DevOps engineers to ensure systems run smoothly and data is safe.