Question: Write a Single Linux Python script that retrieves the following Machine name List of all users and the group they are associated with From /proc/cpuinfo
Write a Single Linux Python script that retrieves the following Machine name List of all users and the group they are associated with From /proc/cpuinfo get the following o Processor o Vendor_id o Model o Model name o Cache All services on machine and their current status This data needs to be collected and formatted in a text file for easy readability.
What I have so far
| Get_CPU_Info.py import os import re import socket #get machine name print(socket.gethostname()) #get cpu information specList = ["processor", "vendor_id", "model", "model name", "cache size"] file = open("/proc/cpuinfo", "r") lines = file.readlines() for spec in specList: for line in lines: if re.search(spec, line): print(line) break #break loop after finding pattern os.system("service --status-all > test.txt") #append to file by double arrows >> #other os.system("systemctl list-units --type service >> test.txt") os.system("systemctl list-unit-files >> test.txt") #All system services on Machine os.system("systemctl list-unit-files --type service >> test.txt") |
If possible to add loops, and lists
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
