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

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

Here are the day 5 tasks of the #90DaysofDevops challenge.


1.?????Write a bash script createDirectoriess1.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.

-???????#!/bin/bash

mkdir day{01..90}

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

-???????#!/bin/bash

Backup_directory="/home/ubuntu/scripts/*"

Backups="/home/ubuntu/backupfolder"

date=$(date +"%d-%b-%Y")

mkdir $Backups/$date

cp -r $Backup_directory $Backups/$date

echo "Backup completed"




3.?????Read About Cron and Crontab, to automate the Script.

Cron: Cron is a job scheduling utility present in Unix-like systems. The crond daemon enables cron functionality and runs in the background. The cron reads the?crontab?(cron tables) for running predefined scripts.

By using a specific syntax, you can configure a cron job to schedule scripts or other commands to run automatically.

-???????Crontab:

·???????Crontab is a configuration file that specifies shell commands to run periodically.

·???????The configuration file is stored in a simple text file, and you can use the crontab command to edit it.


4.?????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.

-???????Here, we will see about users and commands which are used to get information about the users.


1.?????list out all the users in Linux, and use the awk command?with the -F flag. Here, we are accessing a file and printing only the first column with the help of print $1 and awk.


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


2.?????To get the?ID of any username. With the help of the ID command, we can get the ID for any of the users.

id username


3. useradd command, is used to add a new user in Linux Directory. The ID of the user has generated automatically. Username, that we need to set in the command.

sudo useradd username


4.?????Passwd command,?is used to assign a password to a user. After using this command, we have to enter the new password for the user.

passwd username

shashank singh

DevOps Engineer at BJS Hub

9 个月

Very very effective

回复

要查看或添加评论,请登录