Advanced Linux Shell Scripting for DevOps Engineers with User management

Advanced Linux Shell Scripting for DevOps Engineers with User management

It is a #day5 of #90DaysOfDevOps🐧

  1. Write a bash script createDirectories1.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 the third is the end number of directories ) it creates a specified number of directories with a dynamic directory name.

input :

EXAMPLE - 1

vim createDirectory.sh

inside vim editor :

#!/bin/bash

directoryname=$1

startday=$2

endday=$3

for(( i=$startday ; i<=$endday ; i++ ))

do

mkdir $directoryname-$i

done

:wq (save & quiet)

chmod 700 createDirectory.sh (give the executable file permission)

./createDirectory.sh day 1 90

ls

output :

EXAMPLE - 2

./createDirectory.sh movie 20 50

ls

output :

createDirectory.sh

movie-20 movie-21 movie-22 movie-23 movie-24 movie-25 movie-26 movie-27 movie-28 movie-29 movie-30 movie-31 movie-32 movie-33 movie-34 movie-35 movie-36 movie-37 movie-38 movie-39 movie-40 movie-41 movie-42 movie-43 movie-44 movie-45 movie-46 movie-47 movie-48 movie-49 movie-50

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

  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.

    You can use the following command to check the crontab list:-

    crontab -l

    If you want to create a new cron job, use the following command and enter a text editor to add a new cron entry.

    crontab -e

    It is possible to create jobs that you want to reoccur. This process is known as job scheduling. This process is handled by the cron service or a daemon called crond. and crontab -r to remove the current crontab configuration.

    0 0 1, 15 is a cron pattern indicating that this particular command should run on the 1st and 15th of every month at 00:00 and the script output will be appended to the test_c.txt file.

4. Read about User Management

A user is an entity that can manipulate files and perform several other operations. Each user in a Linux operating system is assigned an id. After installation of the OS, ID 0 is assigned to the root user. ID 1–999 are assigned to system users and IDs from 1000 onwards are assigned to the local user.

  • Command to get the id of a user

id username

  • Command to add a user

sudo useradd username

  • Command to assign a password to a user

passwd username

  • Command to access user configuration

cat /etc/passwd

  • Command to delete a user

userdel -r username

  • For switching user account

su username

5. Create 2 users and just display their username

Added 2 users:

sudo useradd -m Thank-You

sudo adduser -m arijit

To display their names we are going to use the following command:

cat /etc/passwd

Thank you very much for giving your valuable time for reading this article !!☺😊

Arijit Manna