Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im now asking this question for a 3rd time so please answer it correctly this time. I am also adding in the code that was

Im now asking this question for a 3rd time so please answer it correctly this time. I am also adding in the code that was given to me before so everyone knows not to use it since its either wrong or incomplete.

CODE GIVEN TO ME TWICE BUT IS WRONG:

import pwd

from os import system

import sys

#Function to create the 4 lists

def createLists(user):

namesList.append(str(user.pw_name))

uIdList.append(str(user.pw_uid))

uGroupList.append(str(user.pw_gid))

uShellList.append(str(user.pw_shell))

def printUserInfo(ID):

print(namesList[ID], uIdList[ID], uGroupList[ID], uShellList[ID])

# Load all user data

try:

allUsers = pwd.getpwall()

except:

print("Cannot get data!")

sys.exit(1)

#Declare empty array lists

namesList = []

uIdList=[]

uGroupList=[]

uShellList=[]

#Iterate through the user data

index = 0

print("USER" + "\t" + "Name")

print()

for user in allUsers:

#Print the required fields

print(str(index)+"\t"+str(user.pw_name)) #+ "\t"+ str(user.pw_uid) + "\t" + str(user.pw_gid) + "\t" + str(user.pw_shell))

#Call function to create lists

createLists(user)

#Increment Key index

index=index+1

while True:

print("Enter number:")

input_data = input()

if input_data == "exit":

break

numberEntered = int(input_data)

printUserInfo(numberEntered)

QUESTION ITSELF:

For this lab you will be accessing a file in your linux OS

File = /etc/passwd

*Create snapshot of your linux distro, so that you can go back if you make a mistake.

*This a scenario you are given, how you accomplish it with Python is up to you. Your challenge will be to logically troubleshoot through it.

Requirements (not given to you in the order they need to happen):

  • Extract from each line of the file only the user name user id group id and user shell.
  • Create a function that opens the file and creates 4 separate lists, incorporate error handling for your file handling.
  • Create a while loop that stays open until the user types exit
  • While the while loop is running the user will see on the screen all the available users on the system. The user can select a specific user and will be prompted which value they want to see (user id, group id, user shell)

PLEASE WHOEVER ANSWERS THIS GIVE ME A CODE THAT WORKS AND WHEN COPY AND PASTING IT INCLUDE ALL THE INDENDTATION WITH IT

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Online Systems For Physicians And Medical Professionals How To Use And Access Databases

Authors: Harley Bjelland

1st Edition

1878487442, 9781878487445

More Books

Students also viewed these Databases questions

Question

Discuss the steps of a generic change project.

Answered: 1 week ago