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

Question 1 Refer to the operations below: Add (10 + 5) Add (4+8) Add (7*2) Add...
Question 1 Refer to the operations below: Add (10 + 5) Add (4+8) Add (7*2) Add (90 – 3) Print list Print peek Remove an item from the list Print list 1.1 Implement the operations above into a Queue structure called q1. 1.2 Implement the operations above into a Stack structure called s1. Name your program Question1_1 for the queue structure and Question1_2 for the stack structure JAVA Language to be used. Please give step by step explanation on how...
Question 1 (20 marks) Refer to the operations below: Add (10 + 5) Add (4+8) Add...
Question 1 Refer to the operations below: Add (10 + 5) Add (4+8) Add (7*2) Add (90 – 3) Print list Print peek Remove an item from the list Print list 1.1 Implement the operations above into a Queue structure called q1. (10) 1.2 Implement the operations above into a Stack structure called s1. (10 Guidelines: Please take note! (a) Name your program Question1_1 for the queue structure and Question1_2 for the stack structure (b) The Java Programmer is required...
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...
Data Structures Use good style. Make sure that you properly separate code into .h/.cpp files. Make...
Data Structures Use good style. Make sure that you properly separate code into .h/.cpp files. Make sure that you add preprocessor guards to the .h files to allow multiple #includes. Overview You will be writing the classes Grade and GradeCollection. You will be writing testing code for the Grade and GradeCollection classes. Part 1 – Create a Grade Class Write a class named Grade to store grade information. Grade Class Specifications Include member variables for name (string), score (double). Write...
Please make sure you add the sources and references on your post. Give an example of...
Please make sure you add the sources and references on your post. Give an example of a B-corporation or a Cooperative or a CSR initiative of a for profit corporation that impressed you for its social responsibility and explain why.
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.
<<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:...
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...
To get full credit for this assignment you must: (1) answer each question - make sure...
To get full credit for this assignment you must: (1) answer each question - make sure you answer every part of question AND (2) respond to at least 2 of your classmates posts (NOTE: You should not just agree/ disagree with the post. You need to provide justified explanation of your agreement/disagreement. Be respectful at all times. Do NOT revise your post after reading other student posts.) In your own words, answer all questions (4 points each): [5pts] Chapter 8...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT