Advanced Linux CLI Operations

Day-5 #90DaysOfDevOps

ยท

2 min read

Advanced Linux CLI Operations

Task1--> Write a Shell Script using either loops or command with start day and end day variables using arguments.

Write a bash script createDirectories.sh that when the script is executed with three given arguments (one is directory name and second is start number of directories and third is the end number of directories ) it creates specified number of directories with a dynamic directory name.

Solution: Create a file createDirectories.sh by using touch createDirectories.sh and give permissions for the file.

nano createDirectories.sh should contain the above script.

Now, execute ./createDirectories.sh day 1 90 which gives the output as follows:

By the above command you can delete the directories at once.

๐Ÿค 

Task 2--> Create a Script to backup all your work done till now.

Solution: Backups are an important part of DvOps Engineers day to day activities as they help you protect your data, applications, and services from unexpected events, such as hardware failures, cyberattacks, natural disasters, or human errors.

create a file backup.sh by touch backup.sh and give permission to it by

The script in the backup.sh is as follows:

Execute the ./backup.sh, which results in different backups at different timestamps. Tar: The common uses of the tar command are to create and extract a tar archive. We can extract the .tgz file by executing tar xf 2023-07-20-18-36-12.tgz. Going into the home directory, we see the scripts directory which was given as a target.

๐Ÿ˜Ž

Task 3-->Cron and Crontab to automate the backup script.

Solution: Cron is the system's main scheduler for running jobs or tasks unattended. However, a cron job is any defined task to run in a given period. It can be a shell script or a simple bash command. 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 located under etc. cat /etc/crontab shows as follows:

crontab -e (to create a crontab)

crontab -l (gives the list of crontabs present)

crontab -e (to create a crontab)

Check Disk Space: In order to check the disk space run the script as follows by executing ./check_disk_space.sh.

The output is as follows:

Check if the used percentage is greater than or equal to the threshold :

The output is as follows at different time intervals.

Thank you for your valuable time.

ย