# Day 5 - Advanced Linux Shell Scripting for DevOps Engineers with User Management

1. Write a bash script [createDirectories.sh](http://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.
    
    Scenario 1: When the script is executed as
    
    `./`[`createDirectories.sh`](http://createDirectories.sh) `dir 1 90`
    
    then it creates 90 directories as `dir1 dir2 dir3 .... dir90`
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685535727375/00b7912c-361d-4894-80d7-1b5fa3543447.png align="center")

1. Scenario 2: When the script is executed as
    
    `./`[`createDirectories.sh`](http://createDirectories.sh) `Movie 20 50` then it creates 50 directories as `Movie20 Movie21 Movie23 ...Movie50`
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685536838565/9f55c374-66e3-4dc7-b874-bbf01860c39f.png align="center")
    
2. **Create a Script to back up all your work done till now.**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685593863863/6b65da8b-8113-4f31-ace4-f886ae3cbff2.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685594127901/a1b3670b-9fcd-42b5-8edc-351fd8265da7.png align="center")
    
3. ### **Read About Cron and Crontab, to automate the backup Script**
    
    **Cron** is an effective and popular command-line utility used to schedule tasks at a specified time and day without user interaction.  
    The scheduled tasks are known as cron jobs while the **crontab** is the list of the file containing the cron jobs.  
    **Crontab** is useful to perform various operations such as handling automated backups, rotating log files, syncing files between remote machines and clearing out temporary folders, etc.  
    The **crond** daemon is the background service that enables cron functionality.
    
    **Linux Crontab Syntax**  
    \* USER\_NAME COMMAND/SCRIPT-TO-EXECUTE  
    │ │ │ │ │  
    │ │ │ │ │  
    │ │ │ │ **|\_\_\_\_\_\_\_\_\_** Day of Week (0 – 6) (0 is Sunday, or use names)  
    │ │ │ |**\_\_\_\_\_\_\_\_\_\_\_\_** Month (1 – 12),\* means every month  
    │ │ |**\_\_\_\_\_\_\_\_\_\_\_\_\_\_** Day of Month (1 – 31),\* means every day  
    │ |**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_** Hour (0 – 23),\* means every hour  
    |**\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_** Minute (0 – 59), \* means every minute
    
    * `crontab -e`: Edit 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.
        
    * `crontab -u <username>`: Edit other user crontab files. This option needs system administrator privileges.
        
    
    To automate the backup script, we can add an entry to the crontab file specifying the schedule for the backup script to run. The syntax for a crontab entry consists of six fields that specify the minute, hour, day of the month, month, day of the week, and command to run. For example, the following crontab entry will run the backup script every day at midnight:
    
    ```plaintext
    0 0 * * * /path/to/backup/script.sh
    ```
    
    This entry specifies that the command (`/path/to/backup/script.sh`) should be run at 12:00am (midnight) every day (`0 0 * * *`).
    
    **Read about User Management**
    
    User management in Linux is the process of creating, modifying, and deleting user accounts on a Linux system. In Linux, each user has a unique username and password, which are used to log in and access the system.
    
    `adduser`: Add a user to the system.  
    `passwd`: Set password fro user  
    `userdel`: Delete a user account and related files.  
    `addgroup`: Add a group to the system.  
    `delgroup`: Remove a group from the system.  
    `usermod`: Modify a user account.  
    `sudo`: Run one or more commands as superuser permissions.
    

### **Create 2 users and just display their Usernames**

To create a new user on Linux, you can use the `adduser` command followed by the username you want to create:

```plaintext
sudo adduser username
```

This will prompt you to enter the user’s password and some additional information such as full name, room number, etc.

To display a list of all users on the system, you can use the below commands to view the `/etc/passwd` file:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685595436739/656bd7c9-5828-4370-bdaf-60ac5a7c7315.png align="center")

***Thank you for reading!!***  
**~Bhaarat**
