Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

INTRO TO UNIX QUESTIONS. Please, Answers only! Thanks. 1. Write a shell script t

ID: 3729308 • Letter: I

Question

INTRO TO UNIX QUESTIONS.

Please, Answers only! Thanks.

1. Write a shell script to validate password strength. Here are a few assumptions for the password string.

-Length should be a minimum of 8 characters.

-Contain both alphabet and number.

-Include both the small and capital case letters.

-If the password doesn’t comply to any of the above conditions, then the script should report it as a “Weak Password” otherwise display a “Strong Password”

2. Please explain what the following shell script is doing

#!/bin/bash
dir=$1
for file in `ls $1/*`
do
    mv $file $file.new
done

Explanation / Answer

1 . SHELL SCRIPT FOR PASSWORD VALIDATION

echo "Enter the password"
read password

length="${#password}"

if test $length -ge 8 ; then

echo "$password" | grep -q [0-9]
  
if test $? -eq 0 ; then

echo "$password" | grep -q [A-Z]

if test $? -eq 0 ; then

echo "$password" | grep -q [a-z]

if test $? -eq 0 ; then

echo "Strong password"

else

echo "Weak Password - Lower Case Characters are missing from Password"

fi

else

echo "Weak Password - Upper Case Characters are missing from Password"

fi

else

echo "Weak Password - Numbers are missing from Password"

fi

else

echo "Weak Password - Password length is less than 8 characters"

fi

OUTPUTS:

Enter the password
helloWorld1
Strong password

Enter the password
helloworld1
Weak Password - Upper Case Characters are missing from Password

Enter the password
HELLOWORLD1
Weak Password - Lower Case Characters are missing from Password

Enter the password
helloWorld
Weak Password - Numbers are missing from Password

Enter the password
helloWo
Weak Password - Password length is less than 8 characters

2. SCRIPT EXPLAINATION

#!/bin/bash
dir=$1 # Reading the first command line argument passed to this script
# First command line argument is the path of a directory
for file in `ls $1/*` # Listing all the files in the path and for each file
do
mv $file $file.new # Moving the file to same location with the .new extenstion (More like renaming it from abc.txt to abc.txt.new)
done

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote