# Day 5: Advance Linux Shell Scripting

* [**Example 1: When the script is executed as**](https://itabhishekyadav.hashnode.dev/day-5-advanced-linux-shell-scripting-with-user-management#heading-example-1-when-the-script-is-executed-as)
    
* [**Example 2: When the script is executed as**](https://itabhishekyadav.hashnode.dev/day-5-advanced-linux-shell-scripting-with-user-management#heading-example-2-when-the-script-is-executed-as)
    
* [**Create a Script to backup all your work done till now.**](https://itabhishekyadav.hashnode.dev/day-5-advanced-linux-shell-scripting-with-user-management#heading-create-a-script-to-backup-all-your-work-done-till-now)
    
* [**Read About Cron and Crontab, to automate the Script.**](https://itabhishekyadav.hashnode.dev/day-5-advanced-linux-shell-scripting-with-user-management#heading-read-about-cron-and-crontab-to-automate-the-script)
    
* [**Read about User Management.**](https://itabhishekyadav.hashnode.dev/day-5-advanced-linux-shell-scripting-with-user-management#heading-read-about-user-management)
    
* [**Create two users and just display their Usernames**](https://itabhishekyadav.hashnode.dev/day-5-advanced-linux-shell-scripting-with-user-management#heading-create-two-users-and-just-display-their-usernames)
    

### 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.

#!/bin/bash

prefix=$1

start=$2

end=$3

for (( i=$start; i&lt;=$end; i++ ))

do

mkdir "${prefix}${i}"

done

~

## **Example 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`

Based on the information provided, it seems that the script “[**createDirectories.sh**](http://createDirectories.sh)” takes three arguments when executed: “day”, “1”, and “90”.

The script likely uses a loop to create 90 directories with names in the format “dayX”, where X ranges from 1 to 90. The loop can be constructed using the shell’s for loop construct and a counter variable that increments on each iteration. Here’s an example implementation of the script in Bash:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682788914040/ca1d38ca-a244-4edb-9852-07e7aab17630.png align="center")

Output :-

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682788984976/eba9f59a-6d4c-4f76-b08b-850e84c4da0d.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686048801456/e3ee8126-fa13-4029-ba74-7ec78b77d968.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686048859123/4533bb67-ba54-4679-9164-a4b63bf2a8b3.png align="center")

### **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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686049069124/cefba11d-5b83-4426-a93d-450d50cb3593.webp align="center")

* `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.
    

# **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.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686049494530/56ffe9a5-4683-4dd1-845c-2df22097b5a2.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686049446238/1c6993fb-bef5-4f90-9b32-f2424046dc5d.png align="center")
