Skip to content

Creating pull request to review and merge the changes until Day_4 changes as a part of BashBlaze-7-Days-of-Bash-Scripting-Challenge #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6964d7b
Adding solution of Day 1 challenge.
raygurudeo Aug 1, 2023
0e0bb45
Updating solution of Day 1 challenge.
raygurudeo Aug 1, 2023
f218836
BashBlaze-7 Day-2 Challenge solution submitted.
raygurudeo Aug 2, 2023
8967d3b
Updating Day2 challenge modification
raygurudeo Aug 2, 2023
8b1e8e2
Updated Day-3 challenge files
raygurudeo Aug 2, 2023
f223be0
Added day 3 scripts
raygurudeo Aug 4, 2023
30f63d1
Added feature1
raygurudeo Aug 4, 2023
56bb78a
Added feature2
raygurudeo Aug 4, 2023
bbe1eed
Added feature3
raygurudeo Aug 4, 2023
3664295
Added feature4
raygurudeo Aug 4, 2023
bebac30
Added main-feature-1.txt
raygurudeo Aug 4, 2023
635ba1b
Added main-feature-2
raygurudeo Aug 4, 2023
40cafbe
Merge branch 'main' into dev
raygurudeo Aug 4, 2023
5a1fdb1
Feature 5 added
raygurudeo Aug 4, 2023
d58d7de
Merge pull request #1 from raygurudeo/dev
raygurudeo Aug 4, 2023
b9728a2
Update feature1.txt on remote manually
raygurudeo Aug 4, 2023
a5d5dd4
Added feature 7
raygurudeo Aug 4, 2023
ead0ca0
Added feature 6
raygurudeo Aug 4, 2023
14f5f2e
Added feature 6
raygurudeo Aug 4, 2023
1b14e74
Feature 8 Added
raygurudeo Aug 4, 2023
33c168d
Added feature 9
raygurudeo Aug 4, 2023
2b83a84
Added feature10.txt
raygurudeo Aug 4, 2023
db6bb39
Merge branch 'dev' of https://github.com/raygurudeo/BashBlaze-7-Days-…
raygurudeo Aug 4, 2023
280fb8c
Added feature 11
raygurudeo Aug 4, 2023
e9450b7
Added Feature 11
raygurudeo Aug 4, 2023
43ab1c4
Added Feature 12
raygurudeo Aug 4, 2023
5180d8e
Added feature 13
raygurudeo Aug 4, 2023
57e492c
Merge branch 'dev' of https://github.com/raygurudeo/BashBlaze-7-Days-…
raygurudeo Aug 4, 2023
e35360a
Revert "Updated Day-3 challenge files"
raygurudeo Aug 4, 2023
0d2be9a
Revert "Added day 3 scripts"
raygurudeo Aug 4, 2023
c01f240
Revert "Revert "Added day 3 scripts""
raygurudeo Aug 4, 2023
1f19f57
Revert "Added day 3 scripts"
raygurudeo Aug 4, 2023
ed79e51
Revert "Revert "Added day 3 scripts""
raygurudeo Aug 4, 2023
6625e87
Added Day_3 Day_4 and Day_5challenges
raygurudeo Aug 4, 2023
844a287
deleted unusual files
raygurudeo Aug 4, 2023
9679df9
Added Day_3, Day_4 and Day_5 challenges.
raygurudeo Aug 4, 2023
c62616a
Added monitor_process.sh script
raygurudeo Aug 5, 2023
9d816ea
Added changes until Day_6 challenge
raygurudeo Aug 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Challenges/Day_1/Day_1_Basics_Solution.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
##############################################################################################
#!/bin/bash #
##############################################################################################
# Author : Gurudeo ray #
##############################################################################################
# #
# Usage : Created this script to full fill Day 1 Bashblaze challenge #
# #
##############################################################################################

echo "Created this script to full fill Day 1 Bashblaze challenge"

#Defining 2 integer variable and assigning them a value
num1=2
num2=5

#Printing sum of num1 and num2
echo "Sum of $num1 and $num2 = $( expr $num1 + $num2 )"

#Built-in variables
echo $HOSTNAME
echo $BASH
echo $#
echo $HOME

#finding file name in home directoy and it's subdirectory with .jpg extension
find /home -name "*.jpg"
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ Create a single bash script that completes all the Tasks mentioned above. Add co
To submit your entry, create a GitHub repository and commit your script to it.

Good luck with Day 1 of the Bash Scripting Challenge! Tomorrow, the difficulty will increase as we move on to more advanced concepts. Happy scripting!

93 changes: 93 additions & 0 deletions Challenges/Day_2/Day_2_Challenge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Day 2 Bash Scripting Challenge - Interactive File and Directory Explorer
Welcome to Day 2 of the Bash Scripting Challenge! In this challenge, you will create a bash script that serves as an interactive file and directory explorer. The script will allow you to explore the files and directories in the current path and provide a character counting feature for the user's input.

Challenge Description
The script will have two main parts:

Part 1: File and Directory Exploration
Upon execution without any command-line arguments, the script will display a welcome message and list all the files and directories in the current path.
For each file and directory, the script will print its name and size in human-readable format (e.g., KB, MB, GB). This information will be obtained using the ls command with appropriate options.
The list of files and directories will be displayed in a loop until the user decides to exit the explorer.
Part 2: Character Counting
After displaying the file and directory list, the script will prompt the user to enter a line of text.
The script will read the user's input until an empty string is entered (i.e., the user presses Enter without any text).
For each line of text entered by the user, the script will count the number of characters in that line.
The character count for each line entered by the user will be displayed.
Example Interaction
$ ./explorer.sh
Welcome to the Interactive File and Directory Explorer!

Files and Directories in the Current Path:
- file1.txt (100 KB)
- dir1 (2 MB)
- script.sh (3 KB)
...

Enter a line of text (Press Enter without text to exit): Hello, this is a sample line.
Character Count: 27

Enter a line of text (Press Enter without text to exit): Another line to count.
Character Count: 25

Enter a line of text (Press Enter without text to exit):
Exiting the Interactive Explorer. Goodbye!
Submission Instructions
Create a bash script named explorer.sh that implements the Interactive File and Directory Explorer as described in the challenge.
Add comments in the script to explain the purpose and logic of each part.
Submit your entry by pushing the script to your GitHub repository.
Congratulations! You've completed Day 2 of the Bash Scripting Challenge. The challenge focuses on Command-Line Argument Parsing and Loops to build an interactive script that explores files, directories, and performs character counting. Happy scripting and exploring!


================================================================================

Directory Backup with Rotation
This is another challenge for Day 2 of the Bash Scripting Challenge! In this challenge, you will create a bash script that performs a backup of a specified directory and implements a rotation mechanism to manage backups.

Challenge Description
Your task is to create a bash script that takes a directory path as a command-line argument and performs a backup of the directory. The script should create timestamped backup folders and copy all the files from the specified directory into the backup folder.

Additionally, the script should implement a rotation mechanism to keep only the last 3 backups. This means that if there are more than 3 backup folders, the oldest backup folders should be removed to ensure only the most recent backups are retained.

The script will create a timestamped backup folder inside the specified directory and copy all the files into it. It will also check for existing backup folders and remove the oldest backups to keep only the last 3 backups.

Example Usage
Assume the script is named backup_with_rotation.sh. Here's an example of how it will look, also assuming the script is executed with the following commands on different dates:

First Execution (2023-07-30):
$ ./backup_with_rotation.sh /home/user/documents
Output:

Backup created: /home/user/documents/backup_2023-07-30_12-30-45
Backup created: /home/user/documents/backup_2023-07-30_15-20-10
Backup created: /home/user/documents/backup_2023-07-30_18-40-55
After this execution, the /home/user/documents directory will contain the following items:

backup_2023-07-30_12-30-45
backup_2023-07-30_15-20-10
backup_2023-07-30_18-40-55
file1.txt
file2.txt
...
Second Execution (2023-08-01):
$ ./backup_with_rotation.sh /home/user/documents
Output:

Backup created: /home/user/documents/backup_2023-08-01_09-15-30
After this execution, the /home/user/documents directory will contain the following items:

backup_2023-07-30_15-20-10
backup_2023-07-30_18-40-55
backup_2023-08-01_09-15-30
file1.txt
file2.txt
...
In this example, the script creates backup folders with timestamped names and retains only the last 3 backups while removing the older backups.

Submission Instructions
Create a bash script named backup_with_rotation.sh that implements the Directory Backup with Rotation as described in the challenge.

Add comments in the script to explain the purpose and logic of each part.

Submit your entry by pushing the script to your GitHub repository.

Congratulations on completing Day 2 of the Bash Scripting Challenge! The challenge focuses on creating a backup script with rotation capabilities to manage multiple backups efficiently. Happy scripting and backing up!
59 changes: 59 additions & 0 deletions Challenges/Day_2/backup_with_rotation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
##############################################################################################
#!/bin/bash #
##############################################################################################
# Author : Gurudeo ray #
##############################################################################################
# #
# About : Developed a shell script to backup resources, present in the directory provided #
# by a user as a input. #
# #
# #
##############################################################################################
# #
# Execution : ./<script-name> <location to take backup> #
# #
# Example : ./backup_with_rotation.sh /home/guru/Documents/ #
# #
##############################################################################################

# Taking directory input from user
backup_input_dir=$1

# Latest timestamp
time_stamp="$(date +'%Y-%m-%d_%H-%M-%S')"

# Locatin to store all the backups
backup_storage_location=$backup_input_dir"/backup_"$time_stamp

# Backup file name with latest timestamp
backup_file_name=backup_$time_stamp"".tar.gz

# Creating backup storage location (storage directory)
mkdir -p $backup_storage_location

# Taking backup and storing at the backup storage location
tar -cvf ${backup_storage_location}/${backup_file_name} ${backup_input_dir} 2>/dev/null 1>/dev/null
if [ $? -eq 0 ]; then
echo "Backup created: $backup_storage_location"
else
echo "Please enter valid directory name."
fi

# Steps to keep latest 3 backups and delete old backups
for backup_list_item in $(ls -t $backup_input_dir | tail -n +4 | grep backup)
do
rm -r $backup_input_dir/$backup_list_item
done



# Solution 1 (If we have more thank 1 extra backup except latest 3)
#solution 2 (if we have only one extra backup except latest 3)
# rm -r $backup_input_dir/$(ls -t $backup_input_dir | awk 'NR>3' | grep backup)

#solution 3 (if we have only one extra backup except latest 3)
# rm -r $backup_input_dir/$(ls -t $backup_input_dir | tail -n +4 | grep backup)


#Dont forget to Give your script executable permission
#chmod +x backup_with_rotation.sh
32 changes: 32 additions & 0 deletions Challenges/Day_2/explorer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
##############################################################################################
#!/bin/bash #
##############################################################################################
# Author : Gurudeo ray #
##############################################################################################
# #
# About : Developed a script to full fill Day 2 Bashblaze challenge (Interactive File and #
# Directory Explorer) #
# #
##############################################################################################

echo "Welcome to Day2 chalenge"

#Printing all the file and directroies with their size in human redable format
echo "Files and directories in current path: "
ls -lh | awk -F " " '{ print $9 " ("$5")"}'

isCondition=true

#Creating interactive while loop to count characters provided by user as a input
while( $isCondition ); do
count=0
read -p "Enter a line or characters (Press enter without any input to exit): " inputstring
if [[ $inputstring != "" ]];then
for(( i=0; i<${#inputstring}; i++ )); do
$(( count++ )) 2>/dev/null
done
echo "Character count : $count"
else
exit;
fi
done
57 changes: 57 additions & 0 deletions Challenges/Day_3/day_3_usermgm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Challenge: User Account Management

In this challenge, you will create a bash script that provides options for managing user accounts on the system. The script should allow users to perform various user account-related tasks based on command-line arguments.

### Part 1: Account Creation

1. Implement an option `-c` or `--create` that allows the script to create a new user account. The script should prompt the user to enter the new username and password.

2. Ensure that the script checks whether the username is available before creating the account. If the username already exists, display an appropriate message and exit gracefully.

3. After creating the account, display a success message with the newly created username.

### Part 2: Account Deletion

1. Implement an option `-d` or `--delete` that allows the script to delete an existing user account. The script should prompt the user to enter the username of the account to be deleted.

2. Ensure that the script checks whether the username exists before attempting to delete the account. If the username does not exist, display an appropriate message and exit gracefully.

3. After successfully deleting the account, display a confirmation message with the deleted username.

### Part 3: Password Reset

1. Implement an option `-r` or `--reset` that allows the script to reset the password of an existing user account. The script should prompt the user to enter the username and the new password.

2. Ensure that the script checks whether the username exists before attempting to reset the password. If the username does not exist, display an appropriate message and exit gracefully.

3. After resetting the password, display a success message with the username and the updated password.

### Part 4: List User Accounts

1. Implement an option `-l` or `--list` that allows the script to list all user accounts on the system. The script should display the usernames and their corresponding user IDs (UID).

### Part 5: Help and Usage Information

1. Implement an option `-h` or `--help` that displays usage information and the available command-line options for the script.

### Bonus Points (Optional)

If you want to challenge yourself further, you can add additional features to the script, such as:

- Displaying more detailed information about user accounts (e.g., home directory, shell, etc.).
- Allowing the modification of user account properties (e.g., username, user ID, etc.).

Remember to handle errors gracefully, provide appropriate user prompts, and add comments to explain the logic and purpose of each part of the script.

## [Example Interaction: User Account Management Script](./example_interaction_with_usr_acc_mgmt.md)


## Submission Instructions

Create a bash script named `user_management.sh` that implements the User Account Management as described in the challenge.

Add comments in the script to explain the purpose and logic of each part.

Submit your entry by pushing the script to your GitHub repository.

Good luck with the User Account Management challenge! This challenge will test your ability to interact with user input, manage user accounts, and perform administrative tasks using bash scripting. Happy scripting and managing user accounts!
45 changes: 45 additions & 0 deletions Challenges/Day_3/example_interaction_with_usr_acc_mgmt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Here's an example how the interaction with the User Account Management script might look:

> Assume the script is named user_management.sh. Let's go through different scenarios:

![1](https://github.com/prajwalpd7/BashBlaze-7-Days-of-Bash-Scripting-Challenge/assets/71492927/653bc7fb-ac50-4089-87fa-a6c3f616bc48)


### Scenario 1: Create a New User

![2](https://github.com/prajwalpd7/BashBlaze-7-Days-of-Bash-Scripting-Challenge/assets/71492927/b472a087-ae23-4d7b-bf4f-95ceca45f6e4)


### Scenario 2: Create a User with an Existing Username

![3](https://github.com/prajwalpd7/BashBlaze-7-Days-of-Bash-Scripting-Challenge/assets/71492927/fc664ca3-6c81-4370-b968-f66a07adf9af)


### Scenario 3: Delete a User Account

![4](https://github.com/prajwalpd7/BashBlaze-7-Days-of-Bash-Scripting-Challenge/assets/71492927/10fce4ff-894a-4385-8a17-dbf8991fba8c)


### Scenario 4: Delete a Non-Existing User Account

![5](https://github.com/prajwalpd7/BashBlaze-7-Days-of-Bash-Scripting-Challenge/assets/71492927/55d1c5ea-6ddb-4b81-9e4c-579b34961a0a)


### Scenario 5: Reset Password

![6](https://github.com/prajwalpd7/BashBlaze-7-Days-of-Bash-Scripting-Challenge/assets/71492927/d2177cbe-3896-40d8-b5ad-3d7b77cb4411)


### Scenario 6: List All User Accounts

![7](https://github.com/prajwalpd7/BashBlaze-7-Days-of-Bash-Scripting-Challenge/assets/71492927/4fc84ea5-ca2d-4438-ad7f-a47980edb3f9)


### Scenario 7: Help and Usage Information

![8](https://github.com/prajwalpd7/BashBlaze-7-Days-of-Bash-Scripting-Challenge/assets/71492927/7818c35c-29b6-44d4-ae63-c12918bdc806)


Please note that the actual output might differ based on your implementation of the script. Also, ensure that you handle different edge cases and error scenarios gracefully to make the script user-friendly and robust.

This Markdown file demonstrates the interaction with the User Account Management script, showcasing various scenarios and expected outputs. The examples provide a clear understanding of how the script works and how users can interact with it.
Loading