Table of contents
- Task 1. Write a bash script createDirectories.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 third is the end number of directories ) it creates a specified number of directories with a dynamic directory name.
- Task 2. Create a Script to backup all your work done till now.
- Task 3.What are Cron and Crontab?
- Task 4. User Management System in Linux
- Task 5.Create 2 users and just display their Usernames
- Thank you for reading! Happy Learning!!
Task 1. Write a bash script createDirectories.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 third is the end number of directories ) it creates a specified number of directories with a dynamic directory name.
Here's how to use the script:
Type the following command - vim createDirectories.sh
and press Enter to create a new file called createDirectories.sh
and open it in Vim for editing.
In the Vim editor, press
i
to enter insert mode, which allows you to type and edit the contents of the file.After entering press Esc button and :wq to save and quit from the Vim editor.
Make the script executable by running the following command:
chmod +x
createDirectories.sh
.Example 1:When the script is executed as
./
createDirectories.sh
day 1 90
then it creates 90 directories as day1 day2 day3 .... day90 .
Task 2. Create a Script to backup all your work done till now.
The above script will help us create a compressed backup archive of a specified directory and save it in a specified backup directory.
Backups are crucial for DevOps because they provide a safety net in case of data loss, system failures, or other unexpected events that could result in downtime or data corruption. By creating regular backups of your system and data, you can quickly restore your infrastructure to a previous state, minimizing the impact of any issues that may arise.
Task 3.What are Cron and Crontab?
Cron is a time-based job scheduler in Unix-like operating systems that allows users to schedule commands or scripts to run automatically at specified intervals or specific times. It is a powerful tool for automating repetitive tasks, such as backups, system maintenance, and running scripts.
The crontab file consists of lines that contain six fields separated by spaces or tabs. The fields represent, in order, the minute, hour, day of the month, month, day of the week, and the command to be executed. An asterisk (*) can be used as a wildcard to indicate all possible values in a field.
Some Crontab Commands:
crontab -e
: This command is used to edit the current user's crontab file. It opens the file in the default editor specified in theVISUAL
orEDITOR
environment variable.crontab -l
: This command lists the current user's cron jobs in the terminal.crontab -r
: This command removes the current user's crontab file, deleting all scheduled cron jobs.crontab -i
: This command prompts the user for confirmation before deleting the crontab file.
This crontab entry will run the script /path/to/backup_script.sh
every day at 2am. The >>
operator is used to append the output of the script to a log file located at /path/to/backup.log
Task 4. User Management System in Linux
In Linux, user management is typically done using command-line tools such as useradd, usermod, and userdel. Here are some common tasks involved in user management in Linux:
Creating a new user account:To create a new user account, use the
useradd
command followed by the username you want to create.Setting a password for a user: To set a password for a user, use the
passwd
command followed by the username.Deleting a user account: To delete a user account, use the
userdel
command followed by the username.Modifying user account settings: To modify user account settings, use the
usermod
command.
Task 5.Create 2 users and just display their Usernames
Use the useradd
command to create the users. For example, to create a user named "audi", do the same for "BMW" enter:
To check if the users are created or not, run the command: cat /etc/passwd.
The new users will be displayed at last.