From 75a7e66b2df5db723747ef92041b62afe6d48f3f Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 31 Jul 2023 09:23:23 +0000 Subject: [PATCH 1/3] solution added --- Challenges/day1_solution.script.sh | 62 ++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 Challenges/day1_solution.script.sh diff --git a/Challenges/day1_solution.script.sh b/Challenges/day1_solution.script.sh new file mode 100755 index 0000000..e6ad78f --- /dev/null +++ b/Challenges/day1_solution.script.sh @@ -0,0 +1,62 @@ +##################################################################################### +# Author: Sasiram Beeke +# Date: 31/07/2023 +# Description: Basics of shell scripting. +# Tip: to execute shell give permision +x scriptname +##################################################################################### + +#!/bin/bash +echo '############### Task1 Comments start here #####################################' +echo '############### With single lineComment #######################################' +echo "welcome to my first example for single line comment" +#echo "this line us for comment purpose" +echo "single line comment example ends here" ## in this by usng # symbol we can give single line comment +echo '############### using << With multi line comment ##############################' +< Date: Tue, 1 Aug 2023 16:42:16 +0000 Subject: [PATCH 2/3] day2 solution added --- Challenges/Day_2/backup_with_rotation.sh | 25 +++++++++++++++++++ Challenges/Day_2/explorer.sh | 22 ++++++++++++++++ .../backup_2023-08-01-16-19-01/f1.txt | 0 .../backup_2023-08-01-16-19-01/f2.txt | 0 .../backup_2023-08-01-16-19-01/f3.txt | 0 .../test/backup_2023-08-01-16-21-13/f1.txt | 0 .../test/backup_2023-08-01-16-21-13/f2.txt | 0 .../test/backup_2023-08-01-16-21-13/f3.txt | 0 .../backup_2023-08-01-16-19-01/f1.txt | 0 .../backup_2023-08-01-16-19-01/f2.txt | 0 .../backup_2023-08-01-16-19-01/f3.txt | 0 .../backup_2023-08-01-16-19-01/f1.txt | 0 .../backup_2023-08-01-16-19-01/f2.txt | 0 .../backup_2023-08-01-16-19-01/f3.txt | 0 .../backup_2023-08-01-16-21-13/f1.txt | 0 .../backup_2023-08-01-16-21-13/f2.txt | 0 .../backup_2023-08-01-16-21-13/f3.txt | 0 .../test/backup_2023-08-01-16-21-16/f1.txt | 0 .../test/backup_2023-08-01-16-21-16/f2.txt | 0 .../test/backup_2023-08-01-16-21-16/f3.txt | 0 .../backup_2023-08-01-16-19-01/f1.txt | 0 .../backup_2023-08-01-16-19-01/f2.txt | 0 .../backup_2023-08-01-16-19-01/f3.txt | 0 .../backup_2023-08-01-16-19-01/f1.txt | 0 .../backup_2023-08-01-16-19-01/f2.txt | 0 .../backup_2023-08-01-16-19-01/f3.txt | 0 .../backup_2023-08-01-16-21-13/f1.txt | 0 .../backup_2023-08-01-16-21-13/f2.txt | 0 .../backup_2023-08-01-16-21-13/f3.txt | 0 .../backup_2023-08-01-16-19-01/f1.txt | 0 .../backup_2023-08-01-16-19-01/f2.txt | 0 .../backup_2023-08-01-16-19-01/f3.txt | 0 .../backup_2023-08-01-16-19-01/f1.txt | 0 .../backup_2023-08-01-16-19-01/f2.txt | 0 .../backup_2023-08-01-16-19-01/f3.txt | 0 .../backup_2023-08-01-16-21-13/f1.txt | 0 .../backup_2023-08-01-16-21-13/f2.txt | 0 .../backup_2023-08-01-16-21-13/f3.txt | 0 .../backup_2023-08-01-16-21-16/f1.txt | 0 .../backup_2023-08-01-16-21-16/f2.txt | 0 .../backup_2023-08-01-16-21-16/f3.txt | 0 .../test/backup_2023-08-01-16-22-21/f1.txt | 0 .../test/backup_2023-08-01-16-22-21/f2.txt | 0 .../test/backup_2023-08-01-16-22-21/f3.txt | 0 Challenges/Day_2/test/f1.txt | 0 Challenges/Day_2/test/f2.txt | 0 Challenges/Day_2/test/f3.txt | 0 Challenges/Day_2/test1/f4.txt | 0 Challenges/Day_2/test1/f5.txt | 0 Challenges/Day_2/test1/f6.txt | 0 Challenges/Day_2/test3/f7.txt | 0 Challenges/Day_2/test3/f8.txt | 0 Challenges/Day_2/test3/f9.txt | 0 53 files changed, 47 insertions(+) create mode 100755 Challenges/Day_2/backup_with_rotation.sh create mode 100755 Challenges/Day_2/explorer.sh create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f3.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-13/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-13/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-13/f3.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f3.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f3.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f3.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-16/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-16/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-21-16/f3.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-19-01/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-19-01/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-19-01/f3.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f3.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/f3.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f3.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f3.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f3.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/f3.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/f1.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/f2.txt create mode 100644 Challenges/Day_2/test/backup_2023-08-01-16-22-21/f3.txt create mode 100644 Challenges/Day_2/test/f1.txt create mode 100644 Challenges/Day_2/test/f2.txt create mode 100644 Challenges/Day_2/test/f3.txt create mode 100644 Challenges/Day_2/test1/f4.txt create mode 100644 Challenges/Day_2/test1/f5.txt create mode 100644 Challenges/Day_2/test1/f6.txt create mode 100644 Challenges/Day_2/test3/f7.txt create mode 100644 Challenges/Day_2/test3/f8.txt create mode 100644 Challenges/Day_2/test3/f9.txt diff --git a/Challenges/Day_2/backup_with_rotation.sh b/Challenges/Day_2/backup_with_rotation.sh new file mode 100755 index 0000000..52dc694 --- /dev/null +++ b/Challenges/Day_2/backup_with_rotation.sh @@ -0,0 +1,25 @@ +################################################################### +# Author: Sasiram Beeke +# Date: 01/08/2023 +# Description: Interactive File and Directory Explorer +# Tip: to execute shell give permision +x scriptname +################################################################### + +#!/bin/bash +# accept argument and assing it to source_dir variable +source_dir=$1 +# create timestamp and store it to timestamp variable +timestamp=$(date +%Y-%m-%d-%H-%M-%S) +# Create the backup folder name using the timestamp +dir_name="backup_${timestamp}" +backup_folder="${source_dir}/${dir_name}" +mkdir "${backup_folder}" +#The script uses rsync to copy the contents of the source directory to the backup folder. +#The rsync command ensures that the backup folder itself is excluded from the copy. +rsync -av --exclude="${dir_name}" "$source_dir/" "$backup_folder" +# Find and remove older backups, retaining only the last 3 backups +find "$source_dir" -maxdepth 1 -type d -name "backup_*" | sort | head -n -3 | xargs rm -rf +# Print a success message +echo "Backup created: $backup_folder" + + diff --git a/Challenges/Day_2/explorer.sh b/Challenges/Day_2/explorer.sh new file mode 100755 index 0000000..1acb242 --- /dev/null +++ b/Challenges/Day_2/explorer.sh @@ -0,0 +1,22 @@ +################################################################### +# Author: Sasiram Beeke +# Date: 01/08/2023 +# Description: Interactive File and Directory Explorer +# Tip: to execute shell give permision +x scriptname +################################################################### + +#!/bin/bash +echo "Welcome to the Interactive File and Directory Explorer!" +echo "Files and Directories in the Current Path:" +ls -lh| awk '{print $9, "(" $5 ")"}' +while true; do + # Ask the user if they want to exit the explorer + read -p "Enter a line of text (press Enter without text to exit):" input + + # Check the user's choice + if [[ -z "$input" ]];then + break + fi + echo "Character count:$(echo -n "$input" | wc -m)" +done + echo "Exiting the Interactive Explorer. Goodbye!" diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-13/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-13/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-13/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-13/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-13/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-13/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-16/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-16/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-16/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-16/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-21-16/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-21-16/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-19-01/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-19-01/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-19-01/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-19-01/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-19-01/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-19-01/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-13/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-19-01/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/backup_2023-08-01-16-19-01/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/backup_2023-08-01-16-21-13/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/backup_2023-08-01-16-21-16/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/f1.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/f2.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/backup_2023-08-01-16-22-21/f3.txt b/Challenges/Day_2/test/backup_2023-08-01-16-22-21/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/f1.txt b/Challenges/Day_2/test/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/f2.txt b/Challenges/Day_2/test/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test/f3.txt b/Challenges/Day_2/test/f3.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test1/f4.txt b/Challenges/Day_2/test1/f4.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test1/f5.txt b/Challenges/Day_2/test1/f5.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test1/f6.txt b/Challenges/Day_2/test1/f6.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test3/f7.txt b/Challenges/Day_2/test3/f7.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test3/f8.txt b/Challenges/Day_2/test3/f8.txt new file mode 100644 index 0000000..e69de29 diff --git a/Challenges/Day_2/test3/f9.txt b/Challenges/Day_2/test3/f9.txt new file mode 100644 index 0000000..e69de29 From 95d75aafe7106cca55b2517c5cab645b644b7165 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 2 Aug 2023 17:23:52 +0000 Subject: [PATCH 3/3] task3 solution added --- Challenges/Day_3/user_management.sh | 125 ++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100755 Challenges/Day_3/user_management.sh diff --git a/Challenges/Day_3/user_management.sh b/Challenges/Day_3/user_management.sh new file mode 100755 index 0000000..17281d5 --- /dev/null +++ b/Challenges/Day_3/user_management.sh @@ -0,0 +1,125 @@ +#!/bin/bash +# check if a username exists +username_exists() { + if id "$1" &>/dev/null; then + return 0 # Username exists + else + return 1 # Username does not exist + fi +} + +# create a new user account +create_user() { + read -p "Enter the new username: " new_username + if username_exists "$new_username"; then + echo "Error: Username already exists. Please choose a different username." + exit 1 + fi + + read -s -p "Enter the password for the new user: " new_password + echo + read -s -p "Confirm the password: " confirm_password + echo + + if [ "$new_password" != "$confirm_password" ]; then + echo "Error: Passwords do not match. User account creation failed." + exit 1 + fi + + # Create the new user account + sudo useradd -m "$new_username" &>/dev/null + echo "$new_username:$new_password" | sudo chpasswd + echo "User account '$new_username' created successfully." +} + +# delete an existing user account +delete_user() { + read -p "Enter the username to be deleted: " del_username + if ! username_exists "$del_username"; then + echo "Error: Username does not exist. Deletion failed." + exit 1 + fi + + # Delete the user account + sudo userdel -r "$del_username" &>/dev/null + echo "User account '$del_username' deleted successfully." +} + +# reset the password of an existing user account +reset_password() { + read -p "Enter the username for password reset: " reset_username + if ! username_exists "$reset_username"; then + echo "Error: Username does not exist. Password reset failed." + exit 1 + fi + + read -s -p "Enter the new password for the user: " new_password + echo + read -s -p "Confirm the new password: " confirm_password + echo + + if [ "$new_password" != "$confirm_password" ]; then + echo "Error: Passwords do not match. Password reset failed." + exit 1 + fi + + # Reset the user's password + echo "$reset_username:$new_password" | sudo chpasswd + echo "Password for user '$reset_username' reset successfully." +} + +# list all user accounts on the system +list_users() { + echo "List of user accounts:" + echo "Username UID" + echo "-----------------" +# cut -d: -f1,3 /etc/passwd +while IFS=: read -r username _ uid _; do + echo "- $username (UID: $uid)" + done < /etc/passwd +} + +# display usage information and available options +usage() { + echo "Usage: $0 [options]" + echo "Options:" + echo " -c, --create Create a new user account" + echo " -d, --delete Delete an existing user account" + echo " -r, --reset Reset the password of an existing user account" + echo " -l, --list List all user accounts on the system" + echo " -h, --help Display this help message" +} + +# Main script starts here +# Check if there are any command-line arguments +if [ $# -eq 0 ]; then + usage + exit 1 +fi +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -c|--create) + create_user + ;; + -d|--delete) + delete_user + ;; + -r|--reset) + reset_password + ;; + -l|--list) + list_users + ;; + -h|--help) + usage + ;; + *) + echo "Error: Invalid option. Use -h or --help to see available options." + exit 1 + ;; + esac + shift +done +