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

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

ยท

3 min read

  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 the directory name, 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.

Example 1: When the script is executed as

./createDirectories.shday 1 90 then it creates 90 directories as day1 day2 day3 ... day90

Example 2: When the script is executed as

./createDirectories.shMovie 20 50 then it creates 50 directories as Movie20 Movie21 Movie23 ...Movie50

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

Backups are an important part of DevOps Engineer's day to Day activities. So we will right the code.

After that we run the code and record the backup to for backup Directories. The output is:

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

cron and crontab are components in Linux that allow users to automate tasks, including backup scripts, at scheduled intervals.

cron: is a time-based job scheduler in Unix-like operating systems. It runs in the background and executes commands or scripts at predefined times without user intervention.

To access the cron configuration, you can use the following command:

This opens the crontab file for editing. Each line in the crontab file represents a scheduled task. The syntax for a cron job is as follows:

The five asterisks represent the time and date information for scheduling:

  • Minute (0 - 59)

  • Hour (0 - 23)

  • Day of month (1 - 31)

  • Month (1 - 12)

  • Day of week (0 - 6, where 0 is Sunday)

For example, the following cron job runs a backup script every 2 Minutes:

After saving the crontab file, this backup script will automatically execute at the specified time.

  1. Read about User Management

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

Adding 2 users :-

Thank you for reading :)

ย