DevOps Day5 Advanced Linux Shell Scripting for DevOps Engineers with User management
Task 1 — Write a bash script createDirectories.sh that when the script is executed with three given arguments (one is the directory name 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.
Example 1: When the script is executed as
./
createDirectories.sh
day 1 90
then it creates 90 directories as day1 day2 day3 .... day90
Run this script giving full permission as by default it has only read and write permissions.
chmod 777 createdirectories.sh
Task 2- Create a Script to back up all your work done till now.
- Save this script as
backup.sh
and make it executable usingchmod +x
backup.sh
. Then, to run the script, simply execute./
backup.sh
.
This script creates a backup directory, sets a backup file name with the current date and time, creates a compressed tar archive of all files in the current directory and its subdirectories, and saves it to the backup directory.
Task 3 -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.
Crontab is a configuration file that is used to define the schedule and commands for cron jobs. Each user on the system can have their crontab file, which is used to schedule jobs to run under their user account.
Task 4 - Read about User Management.
Creating new user accounts: This involves setting up a new account with a unique username and password, assigning the user to a group with specific privileges, and specifying the user's home directory. To create a user account, you can use the
useradd
command.Modifying user accounts: This includes changing the user's password, updating user information such as email address and phone number, modifying user permissions, and changing the user's group membership. To modify an existing user account, you can use the
usermod
command.Deleting user accounts: This involves removing a user account from the system, deleting the user's files and directories, and revoking the user's access to system resources. To delete an existing user account, you can use the
userdel
command.Managing user groups: This includes creating new groups, adding users to existing groups, and removing users from groups. To manage user groups and permissions, you can use a combination of commands such as
groupadd
,groupdel
,usermod
, andchgrp
.
Task 5 - Create 2 users and just display their Usernames
sudo cat /etc/passwd - command to check if user is created or not.
This creates a new user with the username "user1", "user2" and creates a home directory for them (-m option).
Thank You for Reading the Day 5 Blog.. 👍
Stay connected :
Linkedin: https://www.linkedin.com/in/piyush-chauhan-a93989167/