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

1. 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.

Example 1: When the script is executed as ./createDirectories.sh day 1 90 then it creates 90 directories as day1 day2 day3 …. day90

Step 1: Create a file with .sh using nano command

Done, Successfully created Days directory from 1 -90.

Example 2: When the script is executed as ./createDirectories.sh Movie 20 50 then it creates 30 directories as Movie20 Movie21 Movie23 …Movie50

Step 1: Create a file with .sh using nano command

Step 2 : Give execute permission to the file using chmod command

Done, Successfully created Movie directory from 20 -50.

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

Step 1 : Create a file with .sh using nano comman d and put below inputs.

Step 2: Give execute permission to the file using chmod command and Step 3 : Now, run the file using ./ command

Done, Successfully created backup in backup_20230109153526 directory.

3. What is Cron and Crontab, to automate the backup Script

Cron is the system’s main scheduler for running jobs or tasks unattended. Cron is a time-based scheduling daemon that runs on Unix and Linux systems. It is used to schedule commands or scripts to run automatically at a certain time or date.

Crontabe : To edit, submit or delete in cron a command is used called as crontab which allows user to do. A crontab file is a user file that holds the scheduling information. You can use crontab to run any of your scripts or one-liners every hour, or maybe just three days a week, it’s up to you. Each user can have their own crontab file if they wish, but on large systems root usually disallows this and just uses one main crontab file for the whole system. Root is able to do this because of a file called ‘cron.deny’ and ‘cron.allow’ where root can specify who can and cannot have their own crontab.

How to use crontab to schedule a script at a certain time or date.

1. Open the crontab configuration file by running a command crontab -e

2. Add a new line to the file with the schedule and command you want to run

3. Save and exit the file Cron will automatically run the command or script at the specified time according to the configuration in the crontab file.

4. To check list of current crontab configuration use command crontab -l.

4. What is User Management

As Linux is a multi-user operating system, there is a high need of an administrator, who can manage user accounts, their rights, and the overall system security for User management in Linux. You should know the basics of Linux admin so that you can handle the user accounts and usergroups for user management in Linux such as command line tools like useradd, usermod, gpasswd, passwd and others. Server administrators are likely to use these tools, since they are familiar and very similar across many different distributions. This chapter will focus on these command line tools.

Some Command used in User management in linux

5. Create 2 users and just display their Username

Step 1 : Use sudo useradd command to create a 2 usernames

Step 2 : Use awk command to check username list

Thank you for Reading..!

"Embark on the Journey of Knowledge: Happy Learning Lights Up Your Path."

_Abhi Sagare.