Advanced Linux Shell Scripting

Advanced Linux Shell Scripting for DevOps Engineers with User Management

  1. You have to do the same using Shell Script i.e using either Loops or command with start day and end day variables using arguments -

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

Answer

#!/bin/bash

directoryName=$1
startNumberOfDirectory=$2
endNumberOfDirectory=$3

for num in $(seq "$2" "$3");
do
mkdir $1_$num
echo "$1_$num Directory created"
done

to run this script here we need to give a target backup dir argument

./createDirectories.sh utsav 2 8

  1. Create a Script to back up all your work done till now.

Backups are an important part of DevOps Engineers' day to Day activities The video in References will help you to understand How a DevOps Engineer takes backups (it can feel a bit difficult but keep trying, Nothing is impossible.) Watch this video

In case of Doubts, post it in Discord Channel for #90DaysOfDevOps

here is script for this

#!/bin/bash

src=$@
tgt="/home/space/Backup"

filename=$(date | awk '{ print $2"-"$3"-"$4 }');
echo $filename.tar.gz

tar -czvf $tgt/$filename $src

echo "backup complete"

to run this script here we need to give a target backup dir argument

./script_name.sh /home/ubuntu/90dayofdevops
  1. Read About Cron and Crontab, to automate the backup Script

Cron is the system's main scheduler for running jobs or tasks unattended. A command called crontab allows the user to submit, edit or delete entries to cron. A crontab file is a user file that holds the scheduling information.

Watch This video as a Reference to Task 2 and 3 https://youtu.be/aolKiws4Joc

  1. Read about User Management and Let me know on Linkedin if you're ready for Day 6.

A user is an entity, in a Linux operating system, that can manipulate files and perform several other operations. Each user is assigned an ID that is unique for each user in the operating system. In this post, we will learn about users and commands which are used to get information about the users. After installation of the operating system, the ID 0 is assigned to the root user and the IDs 1 to 999 (both inclusive) are assigned to the system users and hence the ids for local user begins from 1000 onwards.

  1. Create 2 users and just display their Usernames

    to create user in Linux here is command

     sudo adduser username
    

to view a list of all user of linux system here is command in Linux

cd /etc/passwd | tail -5