๐ Day 5: Advanced Linux Shell Scripting for DevOps Engineers with User management.
Tasks 1
So Write a bash script create firstscript.sh that when the script is executed with three given arguments (one is the directory name and second is start number of directories and 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
Save this script to a file named firstscript.sh
and make it executable by running:
You can then execute the script with the desired directory name, Trushid 1 2:
Example 2: When the script is executed as
./
createDirectories.sh
Movie 20 50
then it creates 50 directories as Movie20 Movie21 Movie23 ...Movie50
Save this script to a file named ./
createDirectories.sh
and make it executable by running:
Tasks 2: Create a Script to backup all your work done till now
Creating a backup of your work is important. You can create a Bash script to perform a backup of specific files or directories. Here's an example script that you can use to create a backup:
Save this script to a file, make it executable with chmod +x backupfile
, and then run it. It will create a timestamped backup folder in the specified backup directory and copy the contents of your work directory into it.
Tasks 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.
Cron Expressions:
* * * * *
indicates a job that runs every minute.0 * * * *
indicates a job that runs every hour at the beginning of the hour.0 0 * * *
indicates a job that runs once daily at midnight.0 0 * * 0
indicates a job that runs once weekly on Sunday.Editing Crontab: You can edit your crontab using the
crontab -e
commandListing Crontab Entries: You can list your existing crontab entries using the
crontab -l
command.Removing Crontab Entries: To remove your crontab entries, use the
crontab -r
command.
Create 2 users and just display their Usernames