Skip to main content

Command Palette

Search for a command to run...

Advanced Linux for Shell Scripting with User Management

Updated
2 min readView as Markdown

#day5 of #90dayofDEVOPS

Welcome, fellow DevOps enthusiasts! Today, we’re delving into the world of shell scripting in Linux, exploring how to efficiently manage directories and backups — essential tasks for any DevOps engineer. Additionally, we’ll touch upon user management, a crucial aspect of system administration.

Creating Directories Dynamically Ever wondered how to swiftly create multiple directories? Well, wonder no more! With a simple command, you can generate numerous directories in seconds. For example, to create 90 directories named ‘day1’ through ‘day90’, just execute:

mkdir day{1..90}

Now, let’s take it a step further and automate this process using a shell script.

Task 1: Shell Script to Create Directories We’ll write a bash script, createDirectories.sh, that takes three arguments: directory name, starting number of directories, and ending number of directories. This script dynamically generates directories based on the provided arguments.

#!/bin/bash
dirname=$1
start=$2
end=$3
for ((i=start; i<=end; i++))
do
    mkdir -p "$dirname$i"
done

To use this script, execute it with the desired arguments:

./createDirectories.sh day 1 90

Task 2: Backup Script

Backing up our work is like locking the door before leaving the house — it’s essential for keeping things safe and secure. In this task, we’re going to craft a backup script to automate this vital process. Check out the video for some guidance on how DevOps engineers handle backups.

Task 3: Automating Backups with Cron

Learn about Cron and Crontab to automate the backup script. Cron enables scheduling tasks unattended, while Crontab manages the scheduling information. Stay tuned for Day 6 to dive deeper into user management!

More from this blog

90DaysofDEV-OPSby Rohan0730

21 posts

Advanced Linux for Shell Scripting with User Management