Day 5 - Advanced Linux Shell Scripting for DevOps Engineers with User Management

Day 5 - Advanced Linux Shell Scripting for DevOps Engineers with User Management

ยท

2 min read

As a DevOps engineer, efficient shell scripting is a crucial skill to automate routine tasks and enhance productivity. In this blog post, we will delve into advanced Linux shell scripting with a focus on user management. We'll cover the creation of multiple directories using a script, backup strategies, and user management.

Creating Directories Dynamically

To begin with, let's create a bash script named createDirectories.sh that takes three arguments: directory name, start number, and end number. The script will generate a specified number of directories with dynamic names.

Here's the script:

Execute the script to create 90 directories named day1, day2, ..., day90:

This will create directories named day1, day2, day3, and so on up to day90.

Execute the script to create 50 directories named Movie20, Movie21, ..., Movie50:

Backing Up Your Work

Backups are a fundamental aspect of a DevOps engineer's daily activities. Let's create a simple backup script named backupScript.sh to back up your work. This script will zip the contents of a specified directory and store the backup with a timestamp.

Automating Backups with Cron

To automate the backup script, we can leverage the cron scheduler. Open the crontab file using:

crontab -e

Add the following line to run the backup script daily at 2:00 AM:

0 2 * * * /home/ubuntu/day5/backup_work/backupScript.sh /home/ubuntu/day5/backup_work/backup

Save the file, and cron will execute the backupScript.sh daily at the specified time.

User Management

Now, let's create two users and display their usernames using a simple script:

Run the script to create the users and display their usernames:

In this blog post, we explored advanced Linux shell scripting for DevOps engineers, covering dynamic directory creation, automated backups, and basic user management. These skills are essential for streamlining tasks, improving efficiency, and maintaining a robust DevOps environment. Keep practicing and exploring new ways to automate and enhance your workflow.

I'm confident that this article will prove to be valuable, helping you discover new insights and learn something enriching .

thank you : )

ย