Question

In: Computer Science

Make sure you name files with test_yourname in question 1, 4, and 5 Q1: Add a...

Make sure you name files with test_yourname in question 1, 4, and 5

Q1: Add a user named as test_yourname in linux terminal. Take a screenshot if it has been added to the system file /etc/passwd

Q2: What is grep? And why is it used for? (2 lines only)

Q3: Use grep over a file of your choice, take a screenshot and explain the results.

Q4: Can you store the output of top command in a file named as: test_yourname.txt in such a way that the file is appended and not rewritten? Take a screen shot.

Q5: Set password length policy for test_yourname user, with minimum length of password to be 10 character long.

  • Take screen shot of updated policy
  • Once you have updated the policy, in first try violate the policy, and take screen shot while setting password
  • In second try set the password as per the updated policy, and take the screenshot

Solutions

Expert Solution

1. Added logic to take username and password from user

Instead of taking from user, we can statically define the same variables in program and use them directly.

cat output of /etc/passwd file

To directly add logged in user, you can use username="${whoami}", to direclt add the logged in username.

2. grep is a command line utility for searching any txt files/ string for a matching 'regex'

Ex: In the above screenshot, I have serached for 'gowthami' in password file, if there exists any line containing 'gowthami' it will output the line, otherwise the output will be empty.

3. The above screenshot matches the case of using grep over passwd file.

4. The code do a redirect of top to file, giving ctrl+c breaks the copy operation, and every time we run the script this appends to existig file

#!/bin/bash

while true; do
    echo "$(top -b -n 1)"  | tee -a top-output.log #This redirects output of top to top-output.log file
    sleep 1
done

5. Case where password doesn't meet the requirements (>=10 lower case charecters )

Case meething the requirements

Code to validate the password

#!/bin/bash
if [[ $# -ne 2 ]]; then
    echo "Script requires 2 arguments"
    exit
fi

       username=$1
       password=$2
       echo $password | grep -q -E "[a-z]{10}" #Verifying password meets requirements of length is 10 or more charecters
       if [[ $? -eq 0 ]]; then   #if, yes

            useradd -m -p $password $username
       else
           echo "Password length doesn't match the requirements"
       fi
For your reference, to validate password of length 10 or more characters with at least 1 lower, 1 upper case, 1 digit and 1 special character

echo $password | grep -q -E "[A-Za-z0-9@#$%^&*]{10}" #Verifying password meets requirements of at least 1 Upper, 1 lower, 1 digit, 1 special character and length is 14 or more characters

Related Solutions

Hello, please answer all 3 questions, if possible! :) I will make sure to add 5...
Hello, please answer all 3 questions, if possible! :) I will make sure to add 5 star rating! 29. Which of the following commands may be used to display boot error messages? (Choose all that apply.) a. dmesg | less b. less /var/log/boot c. less /var/log/wtmp d. less /var/log/boot.log 31. Which of the following can be used to obtain detailed performance statistics regarding virtual memory usage? (Choose all that apply.) a. Files stored within the /proc directory. b. The iostat...
<<Importing Data>> Make sure you have downloaded all the data files off Blackboard. There should be...
<<Importing Data>> Make sure you have downloaded all the data files off Blackboard. There should be folders containing images and audio files as well as a selection of CSV and Excel spreadsheets. The following exercises will allow you to practice using MATLAB’s import/export functions. Task 4 – Importing Excel Spreadsheets Exercise: Import the spreadsheet ‘buildings.xls’ which contains all the buildings in the world over 300 metres tall. Plot the number of floors vs. building height using a scatter plot. Reflection:...
1) a)draw the structure of histidine at pH 4 and at pH 8. Make sure you...
1) a)draw the structure of histidine at pH 4 and at pH 8. Make sure you clearly indicate all charges. b)Briefly describe the nature of the H-bonds that stabilize parallel and antiparallel -sheets. How do the H-bonds in these two types of secondary structure differ? You can draw simple diagrams if you wish, but there is no need for detailed structures.
Code the following in C++ and make sure to include all three files required at the...
Code the following in C++ and make sure to include all three files required at the end. Hotdogs – The World’s Greatest Cost Effective Wholesome Nutritious Food Due to world food supply scarcity and the burgeoning populations of the world’s countries, your hot stand business is globalizing to satisfy the world’s desire for a cost effective wholesome nutritious food source. Market studies have shown that tens of billions of people are craving for the eponymous hotdog which will result in...
1. Start a new Visual Studio project and name it GradeAppa. Make sure your project...
1. Start a new Visual Studio project and name it GradeAppa. Make sure your project is a web projectb. Make sure it is using C#2. Add a new folder and name it Grades_Logic3. Inside this new folder create a new web form called “Grades”4. Add a label to hold text “Enter Grade”5. Add a text field in front of the label to receive the grade6. Add another label in a new line to display the text “Participation”7. Place a drop-down...
QUESTION 4: Explain the importance and limitations of current ratio in measuring company’s liquidity (make sure...
QUESTION 4: Explain the importance and limitations of current ratio in measuring company’s liquidity (make sure you refer to the effect of each component included in calculating current ratio). QUESTION 5: Can a company reply on net income as a valid measure of cash needed to pay fixed charges? Explain you answer QUESTION 6: Explain why companies do not include principle payment requirement when calculating earnings to fixed charges ratio. . QUESTION 4: Explain the importance and limitations of current...
QUESTION 11 Make sure your calculator settings are at 4 decimals. Remember to clear out the...
QUESTION 11 Make sure your calculator settings are at 4 decimals. Remember to clear out the cash flow register for each problem. Thanks for a great semester :) (mark true) True False 10 points (Extra Credit)    QUESTION 12 Which of the following are true regarding the Market Risk Premium A. it is the intercept of the security market line B. It is the difference between the market rate of return and the risk free rate C. It tells us...
Discuss the composition of bone and name 5 type Add reference
Discuss the composition of bone and name 5 type Add reference
THIS IS A VERY IMPORTANT QUESTION. PLEASE MAKE SURE YOU DO IT COMPLETELY AND UNDERSTAND THE...
THIS IS A VERY IMPORTANT QUESTION. PLEASE MAKE SURE YOU DO IT COMPLETELY AND UNDERSTAND THE CONCEPTS. VNA Enterprises, Inc. manufactures and sells a single product. A schedule of units sold for 3 months and related expenses are as follows: January February March Production in units 18900 22680 13230 Cost A $47327 $56512 $33549 Cost B $61425 $61425 $61425 Cost C $39123 $46948 $27386 Inspect the data in the table above. 1. Which cost is a variable cost? (Type A,...
Genetics - Worksheet #9 Sex-linkage Problems Name ____________________________________ Date __________ Class_____ Make sure that you show...
Genetics - Worksheet #9 Sex-linkage Problems Name ____________________________________ Date __________ Class_____ Make sure that you show the crosses for each problem. Make sure you include a key telling what letters you are using for example: H is normal and h is hemophiliac. Remember this is sex- linked so you must show sex chromosomes. Use the foil method. Color blindness in humans is sex-linked and recessive. A normal man marries a woman whose father was colorblind but she was not.   Cross:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT