๐Day 5 Task: Advanced Linux Shell Scripting for DevOps Engineers with User management
Table of contents
- ๐Tasks
- ๐Task:- 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.
- ๐Task:- Create a Script to back up all your work done till now.
- ๐Task:- Cron and Crontab, to automate the backup script.
- ๐Task:- Read about User Management.
- ๐Task:- Create 2 users and just display their Usernames
- ๐ Conclusion:
Linux shell scripting for DevOps engineers with user management involves creating scripts that automate various user management tasks on a Linux system. This can include creating users, modifying user properties, managing user groups, and more.
๐ Before we begin, ensure you have basic knowledge of shell scripting and are familiar with the Linux command-line environment.
๐Tasks
๐Task
:- 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.
If you noticed that there are 90 sub-directories in this repository's directory '2023'. What did you think, how did I create 90 directories? Manually one by one or using a script, or a command? All 90 directories within seconds using a simple command. ` mkdir day{1..90}`
๐ https://github.com/nikucse/90DaysOfDevOps/tree/master/2023
Step 1: Create a shell script name vim createDirectories.sh
Step 2: write a shell script
#!/bin/bash
arg=$1
for((i=1; i<=$arg; i++))
do
mkdir "day$i"
echo "Driectory is created day$i"
done
echo " $arg Directories created succefully"
Step 3: execute a script by passing a value e.q 10
chmod 700 backup.sh
๐Task
:- Create a Script to back up all your work done till now.
Step 1: Create a shell script name vim backup.sh
Step 2: write a shell script
#!/bin/bash
backup_dir = "/path/backup"
time_stamp = $(date+'%d-%m-%Y %H:%M:%S')
backup_filename = "backup_${time_stamp}.tar.gz"
backup_sources = "path/source"
tar -czvf "${backup_dir}/${backup_filename}" $backup_sources
if [ $? -eq 0 ]; then
echo "Backup completed successfully. Archive: ${backup_dir}/${backup_filename}"
else
echo "Backup failed. Please check the error messages."
fi
Step 3: execute a script if your file getting permission denied please use chmod 700 backup.sh
๐Task
:- Cron and Crontab, to automate the backup script.
Cron is a time-based job scheduler in Unix-like operating systems that allows you to automate repetitive tasks, such as running a backup script at specific intervals. Crontab (CRON TABle) is a configuration file that specifies the schedule of cron jobs for individual users.
crontab -e
๐Task
:- 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 hence the ids for local user begins from 1000 onwards.
๐Task
:- Create 2 users and just display their Usernames
To create two users and display their usernames, you can use the useradd
command to add the users and then simply display their usernames using the echo
command.
cmd:- useradd -m user1
cmd:- useradd -m user2
๐ฌ For Display user we need to check /etc/passwd
file
tail -n 10 /etc/passwd
or cat /etc/passwd
๐ Conclusion:
Congratulations! ๐ Shell scripting is a method of writing scripts or programs using shell commands and scripting languages to automate tasks and interact with the operating system through the command-line interface (CLI). We hope this blog has given you a Question/Answer ๐ Embrace the Shell power and have fun with your Shell Scripting journey! ๐ช
๐ Did you find this blog helpful? Let us know in the comments below! ๐ And if you have any questions or need further assistance, we're here to help! ๐ค
Happy Shell-Scripting! ๐ปโจ