TABLE OF CONTENTS
📌Introduction:
📌Creating n number of directories using a script
📌How to create Multiple directories, from passing arguments dynamically:
📌What is cron and crontab:
📌Creating a simple backup script and printing its output in a backup.txt file every two minutes using cron job:
📌About User Management in Linux:
📌Create 2 users and just display their Usernames
🔁Conclusion:
Introduction:
In the last blog, we saw the basic of shell scripting now it's time to learn more and get our hands dirty in advanced topics.
In this blog, we are learning about Advanced scripting, how to create multiple folders, how to take backups, what are cron and crontab, how to schedule jobs using crontab and many more.
How to create Multiple directories, from passing arguments dynamically:
If you noticed that there are a total of 90 sub-directories in the directory '2023' of this repository. 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}
Tasks**:**
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 -
So Write a bash script to create directories.sh so that when the script is executed with three given arguments (one is the directory name and the second is the start number of directories and the 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
Example 2: When the script is executed as
./
createDirectories.sh
Movie 20 50
then it creates 50 directories as Movie20 Movie21 Movie23 ...Movie50
what is Cron & Crontab:
An experienced Linux sysadmin knows the importance of running routine maintenance jobs in the background automatically. Linux Cron utility is an effective way to schedule a routine background job at a specific time and/or day on an ongoing basis.
Linux Crontab Format
MIN HOUR DOM MON DOW CMD
Scheduling a Job For a Specific Time The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June at 08:30 AM. Please note that the time field uses 24 hours format. So, for 8 AM use 8, and for 8 PM use 20
30 08 10 06 * /home/Suraj/full-backup
• 30 — 30th Minute
• 08-08 AM
•10— 10th Day
•06 — 6th Month (June)
• * — Every day of the week
Shedule a Job For More Than One Instance (e.g. Twice a Day) The following script takes an incremental backup twice a day every day. This example executes the specified incremental backup shell script (incremental-backup) at 11 and 16:00 every day. The comma-separated value in a field specifies that the command needs to be executed at all the mentioned times.
00 11,16 * * * /home/Suraj/full-backup
00 11,16 ** \* / home/ramesh/bin/incremental-backup
0 — 0th Minute (Top of the hour)
1,16- 11 AM and 4 PM
*— Every day
* Every month
* Every day of the week
About User Management in Linux:
Linux is a multi-user operating system, which means that more than one user can use Linux at the same time. Linux provides a beautiful mechanism to manage users in a system. One of the most important roles of a system administrator is to manage the users and groups in a system.
Groups
In Linux or Unix-based operating systems, we can form groups of users’ accounts. Groups are used to manage the user accounts collectively. We can manage the access permissions for the entire group.
Create 2 users and just display their Usernames
Conclusion 🎉
Check out this reference: https://www.geeksforgeeks.org/user-management-in-linux/
I hope you enjoyed reading this blog. I have one request to all give it a try on your own with some complicated scenarios like having permutations and combinations of permissions 😂. It'll definitely be helpful in your entire career.
Subscribe to my newsletter by visiting my site and also have a look at the consolidated list of all my blogs.
For updates follow me on LinkedIn: Suraj Barik
Cheer