Day 5 Task: Advanced Linux Shell Scripting for DevOps Engineers with User management

Shaikh RahilShaikh Rahil
3 min read

Write a bash script createDirectories.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

Script: Eval is the linux commad which is used to run the argument as a shell command⚙Here we are using three arguments 1st as a name of the directory 2nd as a start number 3rd as a end number.

Output: Here we have to pass the argument while executing the script

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

Creating a Linux backup script is a great way to ensure your system’s data safety and integrity. Linux makes it easy to do so with bash, tar, rsync, and cron. Generally, you’ll want to start by writing a shell script that contains the specified Linux commands.

Script: First we have to give the Source and Destination path and i have used time stamped as a folder name for easy understanding the most important command is

tar -cpzf $destination $source

c: create

v: verbose mode, verbosely list files processed

p: preserve permissions for the new files

z: compress the files in order to reduce the size

f: use archive file or device ARCHIVE

Output:

Read About Cron and Crontab, to automate the backup Script

Corntab is a linux daemon that allows us to run scripts in certain scheduled moments. Crontab files automate backups, system maintenance and other useful tasks. In order to edit the crontab file with the editor you prefer(nano is the easiest), run in a terminal the command

crontab -e
#command to edit crontab

Let’s understand the contrab line format:

minute(0–59) hour(0–23) day(1–31) month(1–12) weekday(0–6) command

Let’s say that we want to run the script everyday at 12:30 a.m. we would type

29 0  * /bin/bash /path/backup_script.sh
#29 stands for the 30 minute
#0 stands for 12 a.m.

Create 2 users and just display their User names

To ADD User 👤

sudo useradd username

To DELETE User🔪

sudo userdell username

Using id command, you can get the ID of any username. Every user has an id assigned to it and the user is identified with the help of this id. By default, this id is also the group id of the user. ✔

id username

To list out all USER in Linux

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

So in this blog we have seen some advance shell scripting concepts, Automating tasks using Crontab,User management such Creating, Deletions of users🚠keep supporting guyzz if your have any queary feel free to ask.

HAPPY LEARNING❤

0
Subscribe to my newsletter

Read articles from Shaikh Rahil directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shaikh Rahil
Shaikh Rahil