Advanced Linux Shell Scripting for DevOps Engineers with User Management.

Write a bash script createDirectories.sh that when the script is executed with three given arguments (one is the directory name and second is the start number of directories and third is the end number of directories ) it creates a specified number of directories with a dynamic directory name.

#!/bin/bash
#############################################################
#Author: Neha Bisen
#Date: 24/07/2023
#Purpose: This script will create 90 directories at once
#############################################################

#Intializing variables
Name_of_dir=$1
start_no=$2
end_no=$3

#Command to create directories
eval mkdir $Name_of_dir{$start_no..$end_no}

Here, the "eval" command takes arguments as input to the command and stores it as one single command.


Create a script to backup all your work done till now.

##########################################################################
#Author: Neha Bisen
#Date: 24/07/2023
#Purpose: This script will take backup
##########################################################################

#Creating Variables 
src=/home/ubuntu/day5
dest=/home/ubuntu/backups
time=$(date +"%Y-%m-%d-%H-%M-%S")
backupfile=$dest/$time.tgz

#Taking Backup
echo "Taking backup on $time"
tar zcvf $backupfile --absolute-names $src

if [ ${?} -eq 0 ]
then
        echo "Backup Complete"
else
        exit 1
fi

Read About Cron and Crontab, to automate the backup Script.

crontab -e

Enter the below code in the last line of crontab,

* * * * * sh/home/ubuntu/day5/backup.sh

first *, -represents minutes

second *, -represents hours

third *, -represents the day of the month

fourth *, -represents month

fith *, -day of week


Read about User Management

User management is a very important part of a DevOps engineer's journey.

User management includes some basic tasks, like

  • Creating Users

  • Deleting Users

  • Password reset

  • Adding user in a group


Create 2 users and just display their Usernames

##########################################################################
#Author: Neha Bisen
#Date: 24/07/2023
#Purpose: This script will take two argument as username and create user
##########################################################################

#Creating variables
user1=$1
user2=$2

#Creating Users
echo "Adding Users $user1 and $user2"
useradd -p test -m $user1
useradd -p test -m $user2

if [ ${?} -eq 0 ]
then
        echo "Users added successfully"
else
        exit 1
fi