In this blog post, we'll explore the creation of directories using a bash script. The objective is to generate a specified number of directories with

In this blog post, we'll explore the creation of directories using a bash script. The objective is to generate a specified number of directories with

dynamic names, allowing users to customize the prefix, start, and end numbers.

Bash scripting is a powerful tool for automating tasks in a Unix-like environment. In this example, we'll create a bash script named createDirectories.sh to generate a series of directories with flexible names.

#!/bin/bash

if [ "$#" -ne 3 ]

then

echo "Usage: $0

<directory_prefix><start_number> <end_number>"

exit 1

fi

prefix=$1

start=$2

end=$3

for (( i=start; i<=end; i++ ))

do

directory="${prefix}${i}"

mkdir "$directory"

echo "Created directory:

$directory"

done

Examples

Let's look at two examples to illustrate the script's usage:

Example 1: Creating Daily Directories

./createDirectories.sh day 1 90 (this command will run after give permission to it)

bash createDirectories.sh day 1 90

This command creates 90 directories named day1, day2, ..., day90

Example 2: Movie Directories

./createDirectories.sh Movie 20 50

This command generates 31 directories named Movie20, Movie21, ..., Movies50

2.Create a Script to backup all your work done till now

Script for DevOps Backup 🚀

Backups play a crucial role in a DevOps Engineer's routine, ensuring the safety and integrity of work. Below is a simple script to automate the backup process.

Script Name: backup_script.sh

Objective: Create a backup of all work done so far

#!/bin/bash

# Set your backup destination

backup_dir="/path/to/backup"

# Create a timestamp for the backup

timestamp=$(date +"%Y%m%d_%H%M%S")

# Create backup folder with timestamp

backup_folder="$backup_dir/backup_$timestamp"

mkdir "$backup_folder"

# Copy important files to the backup folder

cp -r /path/to/your/work/* "$backup_folder"

echo "Backup completed successfully at $timestamp."

Read About Cron and Crontab, to automate the backup Script

Introduction

Cron and crontab are essential tools in Linux for automating tasks. Let's explore how to use them to schedule and automate backups efficiently

Crontab: Command to manage cron jobs.

Cron Expression: Time-based expression defining when a task should run.

Automating Backup Script with Cron

Edit crontab using crontab -e.Add a line to schedule daily backups, e.g., 0 2 * * * /path/to/backup_script.sh.This example runs the script daily at

Automating Backups with Cron

Introduction 🕒

Cron is a powerful tool in Linux for scheduling recurring tasks, allowing us to automate processes like backups. By leveraging crontab, we can effortlessly schedule our backup script to run at specified intervals.

Cron Basics ⏰

Crontab: A command used to manage cron jobs.

Cron Expression: A time-based expression defining when a task should run.

Automating Backup Script with Cron 🚀

Edit crontab: crontab -e Add a line to schedule daily backups, e.g., 0 2 * * * /path/to/backup_script.sh

This example runs the script daily at 2 AM.

Exploring User Management

Understanding Users in Linux 👤

User ID (UID): Unique identifier for each user.

Root User: Assigned ID 0, has administrative privileges.

Local Users: IDs start from 1000 onwards.

User Management Commands 🛠️

whoami: Displays the current username.

id: Shows user and group information.

passwd: Changes user password.

useradd: Adds a new user.

userdel: Deletes a user.

usermod: Modifies user attributes.