Question

In: Computer Science

Write a shell script that will create a new password-type file that contains user information. The...

Write a shell script that will create a new password-type file that contains user information. The file should contain information about the last five users added to the system with each line describing a single user. This information is contained in the last five lines of both the /etc/shadow and the /etc/passwd files. Specifically, you should produce a file where each line for a user contains the following fields: user name, encrypted password, and shell. The fields should be separated using the colon (:) character.

Solutions

Expert Solution

Please find the below shell script for the given scenario. Please copy paste the below script in a file with extension .sh( for example test.sh) and change the permission of the file(add execute permission) using chamod command as shown below and execute the filr as ./test.sh

chmod 755 test.sh

Sample entry of the /etc/passwd files is as follows( here the first column is the user name and the seventh column is users shell )

tom1:x:1000:1000:Vivek Gite:/home/vivek:/bin/bash

Sample entry in /etc/shadow file is as follows( here the first column is the user name and the second column is encrrypted password)

linuxize1:$6$zHvrJMa5Y690smbQ$z5zdL...:18009:0:120:7:14::

So to get the desired output as mentioned in the question, ie 'username:encrypted password:shell of the user' we need to extract the first column(user name [-f 2]) from /etc/passwd using cut command and delimiter as colon (-d:). Then extract the second column(encrypted password [-f 2]) from the /etc/shadow using cut command and delimiter as colon (-d:) . Then extract the 7th column (user shell [-f 7]) from /etc/passwd using cut command and delimiter as colon (-d:).

After extracting each columns, the concatenate all these fileds together using the 'paste' command with colon(:) as delimiter to get the final output. Then write this output to a file with name 'newpass.txt'

The 'tail -n' command is used to get the last 'n' lines from a file. So 'tail -5 /etc/passwd' gives the last 5 lined of the file /etc/passwd.

Please provide your feedback.

Thanks, Happy Learning!


#!/bin/bash

paste --delimiter=':'  <(tail -5 /etc/passwd | cut -d: -f 1) <(tail -5 /etc/shadow | cut -d: -f 2) <(tail -5 /etc/passwd | cut -d: -f 7) > newpass.txt

Related Solutions

Write a brief shell script that will take in a specific file name, prompt the user...
Write a brief shell script that will take in a specific file name, prompt the user whether they would like to gzip, bzip2, or xz compress the file. Depending on response, the script then ought to compress the provided file with the corresponding method
Write a bash script that... create new user ./finalProject user if a new user is to...
Write a bash script that... create new user ./finalProject user if a new user is to be created ask for the new users information and use it when creating the new user add a new printer ./finalProject printer ask anything you need in order to create the new printer (I.e. name) permissions ./finalProject permissions ask what document and permissions the user wants restarting the computer ./finalProject restart
Write a complete shell script that first asks the user to enter a URL. The script...
Write a complete shell script that first asks the user to enter a URL. The script should read the URL into a variable named url. The shell script should then retrieve the file associated with the URL by using the curl command. The output of the curl command should be redirected to a file named html_file. The shell script should then use the grep command to search the file named html_file for the word manhattan. Finally, the shell script should...
Write a script that prompts the user for a pathname of a file or directory and...
Write a script that prompts the user for a pathname of a file or directory and then responds with a description of the item as a file along with what the user's permissions are with respect to it (read, write, execute).
C# Create an application that asks the user to enter their new password. The password must...
C# Create an application that asks the user to enter their new password. The password must be at least 6 characters long. Develop a custom exception handling case that checks for the password length. (hint: use " .Length " built-in method). If the new password is less than 6 characters long the custom exception should output an error message.
Create shell scripts, .sh file. Please include a shebang line at the top of the script...
Create shell scripts, .sh file. Please include a shebang line at the top of the script as well as appropriate comments through out. Write a script that plays a simple “guess the number” game with the user. It should select a random integer in the range [0 - 10], ask the user to guess the value, and provide feedback of the form “too high”, “too low”, or “congratulations” as appropriate. After the correct value is guessed, the script should terminate.
Write a Powershell script to create a Windows user account that is a non-admin user. This...
Write a Powershell script to create a Windows user account that is a non-admin user. This assignment assumes that you already have a Windows VM, with the administrator account created.. To complete the assignment, write the PowerShell script, run it on your VM, and submit the script here.
Please write a shell script called "myfilechecking" to determine whether a file belongs to one of...
Please write a shell script called "myfilechecking" to determine whether a file belongs to one of the following categories: A directory; A scrip file (readable and executable); An executable file (not readable but executable, such as a.out); A regular ascii file (only readable, such as a C source code file); The file cannot be recognized. Your script should display the corresponding information based on the category of the file; The file name should be provided along with your script invocation,...
Write a bash shell script that takes exactly one argument, a file name. If the number...
Write a bash shell script that takes exactly one argument, a file name. If the number of arguments is more or less than one, print a usage message. If the argument is not a file name, print another message. For the given file, print on the screen its content.
3. Write the statements to: • create a user named FooBar with a password of “candybar”...
3. Write the statements to: • create a user named FooBar with a password of “candybar” • assign the payments role created in the previous question to FooBar • assign the create session privilege to FooBar • Show the statements to connect to FooBar 4. For this question, I only need the query statement and not the results. Write the queries that use the user_sys_privs, user_tab_privs, user_role_privs, role_sys_privs and role_tab_privs objects to view the user and role privileges that are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT