# Day - 05

# Advanced Linux Scripting:

**Write a bash script** [**createDirectories.sh**](http://createDirectories.sh) **that when the script is executed with three given arguments (one is 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.**

**Case 1**: When the script is executed as `./`[`createDirectories.sh`](http://createDirectories.sh) `day 1 90` then it creates 90 directories as `day1 day2 day3 .... day90`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690579762582/0a46aaa2-abd5-4981-9787-739f6003042b.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690580099052/b98bc097-9ee8-4498-8fea-3a20460ccbd9.png align="center")

**Case 2**: When the script is executed as `./`[`createDirectories.sh`](http://createDirectories.sh) `Movie 20 50` then creates 50 directories as `Movie20 Movie21 Movie23 ...Movie50`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690580010120/a768464c-e20a-4ee4-a5c0-37c519476d5d.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690580048731/79360257-4afa-4891-97b6-2c28cedba3e0.png align="center")

## Creating a Script to back up all your work done till now.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690582744641/f8c0d51b-f854-40d7-8d26-bd0994d935aa.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690582781152/72bb2974-4841-4b84-9079-7b5c8b7d971d.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690582805469/fbedd51d-df5e-4ce6-ac09-5d231094a69c.png align="center")

# **Cron and Crontab, to automate the backup Script**

Crontab is used to schedule and automate tasks or scripts that need to run at specific intervals or at predefined times.

The syntax for a Crontab entry is divided into five fields, each representing different time elements:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690585104696/1fe46c09-508d-4326-921a-2b2e76c43941.png align="center")

The **crontab** command is used to interact with their crontab files. It is typically located in the **/etc/cron.d/** directory for system-wide tasks or in the user's home directory for individual user-specific tasks.

### **How to Edit Crontab**:

**crontab -e**: Opens the crontab file for the currently logged-in user, allowing you to edit their scheduled tasks. This is the default behavior of the command.

However, if you need to edit the crontab entries for a different user, you can use the following command: **crontab -u username -e**

### **How to List Crontab**:

**crontab -l**: Lists the existing crontab entries for the user, displaying the scheduled tasks and their respective timing. Use **\-u** followed by the username to view the crontab entries of the specified user (**crontab -u username -l**).

### **How to Remove Crontab:**

**crontab -r**: Removes the user's crontab file, effectively deleting all scheduled tasks.

# **User Management in Linux**

In Linux, user management is essential for maintaining security and access control.

**Root user:** is a superuser who has complete administrative privileges over the server. This privilege is granted during the server's setup.

To add a new user to the system, we can use the `useradd` command with the following syntax: **useradd -c "comment" username**

To remove a user account from the system, we use the `userdel` command with the `-r` option to delete the user's home directory along with their account: **userdel -r username**

To modify the properties of an existing user, we can utilize the `usermod` command with the following syntax: **usermod -c "comment" username**

**/etc/passwd** file stores detailed information about all the users created on the server, including their usernames, user IDs, home directories, and more.

**Task 1:** Create 2 users and just display their usernames

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690593932944/7bbe858a-172c-4346-a852-9a07e9eea265.png align="center")
