💠Task 1: Bash Script to Create Dynamic Directories.
Example 1:
Creates 90 directories as day1 day2 day3....day90
using loop
The +x
option specifically sets the execute permission on a file, allowing it to be run as a program.
Run the ./createDirectories.sh
file.
Example 2:
Creates 30 directories as Movie20 Movie21 Movie23....Movie50
using loop
The +x
option specifically sets the execute permission on a file, allowing it to be run as a program.
Run the ./createDirectories.sh Movie 20 50
file.
💠Task 2: Create a Script to backup all your work done till now.
Backups are an important part of DevOps Engineer's Day to Day activities.
Now let's create the backup.sh, a file which we can run and create the backup of the contents that are present in scripts directory.
By using tar
command to archive and also compress the file to create a backup file.
Execution of the backup.sh, you get the following result :
💠Cron and Crontab
◼️ Cron is a time-based job scheduler in Unix-like operating systems. It is used to schedule jobs to run at specific times or dates.
◼️ Crontab is a file that contains a list of cron jobs.
The syntax for a crontab entry is as follows:
COPY
minute hour day month day_of_week command
OR
* * * * *
Some useful commands crontab commands to use in the terminal :
crontab -e
: Edit the crontab file, or create one if it doesn’t already exist.crontab -l
: Display crontab file contents.crontab -r
: Remove your current crontab file.crontab -i
: Remove your current crontab file with a prompt before removal.
◼️The example of crontab entry:
COPY
# Run a backup script every Sunday at 6:00 AM
0 6 * * 0 /path/to/backup-script.sh
◼️Explanation:
0
- Minute field, specifying that the task should run when the minute is 0 (on the hour).6
- Hour field, specifying that the task should run at 6 AM.*
- Wildcard character, meaning "every" for the day of the month and month fields.0
- Day of the week field, specifying that the task should run on Sunday./path/to/
backup-script.sh
- The command or script to be executed.
In this example, the backup script will run every Sunday at 6:00 AM. You can adjust the fields to schedule tasks at different times or on different days. The cron syntax allows for a high degree of flexibility in defining when tasks should be executed.
💠User Management & it's Example in Linux
User management in Linux involves creating, modifying, and deleting user accounts, as well as managing user-related settings and permissions. Here are some commonly used commands for user management:
◼️Creating a User: To add a new user, you can use the adduser
or useradd
command.
◼️Setting Password: To set a password for the user, use the passwd
command.
COPY
passwd username
◼️Deleting a User: To remove a user, use the userdel
command.
COPY
userdel username
◼️Display the Username: To display username use below commands.
🔎Conclusion
The Advanced Linux Shell Scripting course for DevOps Engineers, focusing on user management, equips professionals with crucial skills. Graduates master creating, modifying, and automating user accounts for secure access. This expertise in advanced scripting enhances efficiency and scalability.
Happy learning :)