# Advanced Linux Shell Scripting for DevOps

## 📝 Introduction

This blog will cover the automation of creating multiple directories, the process of taking backups using cron jobs, and the management of users in Linux.

## 📌 Task - 1 Create Multiple Directories by Passing Arguments 📁📁

Example -1

```basic
#! /bin/bash

name="$1"
first_number="$2"
last_number="$3"

for ((i=$2;i<=$3;i++))

do
mkdir -p "/home/nik/Directory/$1$i"
done
```

Output:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690082232426/2cd1b7be-f7b3-48b2-be0e-8f371eba5b5f.png align="center")

Example - 2

Output :

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690082416196/87829e28-99d8-4412-abb4-70736d0bfe67.png align="center")

## 📌 Task - 2 Script to Backup Your Work 📜💾

```basic

#! /bin/bash

# source and destination path
source_path=/home/nik/Directory
Dest_path=/home/nik/backup

# current timestamp
day=$(date "+%Y-%m-%d_%H-%M-%S")

# tar folder
tar -cvf  $Dest_path/Directory.tar.gz$day $source_path
echo "Backup completed successfully"
```

## 📌 Task - 3 What are Cron and Crontab 🕰️🗒️

The **crontab** is a list of commands that you want to run on a regular schedule, and also the name of the command used to manage that list. It allows users to schedule tasks or commands to run at specific intervals or at predefined times. These scheduled tasks are referred to as corn jobs.

Entry in the crontab file to schedule the above script for daily execution at 11:30. /dev/null This refers to the null device, and writing to it is a way to discard the output.

```basic
30 11 * * * /home/nikhil/backup.sh && /dev/null
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690092072487/228e8309-947c-459d-906e-973bc22070b8.png align="center")

## 📌 Task - 4: User Management in Linux 👥🔧

User management in Linux involves creating, managing, and controlling user accounts on the system. Each user account represents a separate identity that can access the system's resources, files, and applications.

```basic
# How to create users in linux

sudo useradd <username>
sudo adduser <username>
```

## 📌 Task - 5 Creating Users and Displaying Usernames 👤👤

```basic
sudo useradd test1
sudo useradd test2
```

```basic
# To check usernames 

id
cat /etc/passwd
awk -F: '{print $1}' /etc/passwd
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690087308682/55e98230-f72f-48f8-8c0b-191cb623785c.png align="center")
