Question: I need help running a code on my linux virtual machine. Whenever i try running the code i get a SyntaxError: multiple statements found while
I need help running a code on my linux virtual machine. Whenever i try running the code i get a "SyntaxError: multiple statements found while compiling a single statement" I will send the code in screen shots below cause typing it here doesnt work.



import platform import os def user groups (fout) : I I A function to add groups associated to each user to the output file os . system ("cat /etc/passwd > users. txt") # Storing the users in a temporary file try: f = open ( 'users . txt ' , 'r' ) except FileNotFoundError: print ("File is not present") lines = f. readlines () userslist = for line in lines: userslist . append (line . split (": ") [0]) f . close () # Writing the fetched users to output file fout . write ("\\USER GROUPS: \ ") for user in userslist: os . system (f"groups {user} > usergroups. txt") try : f temp = open ( 'usergroups . txt' , 'r' ) except FileNotFoundError: print ("File is not present") line = f temp . readline () . strip () . split (': ") # User usr = line [0] # Groups associated to this user groups = line [1] . strip () .split (" ") f_temp . close () # Writing user fout . write (usr + str (": \\") ) # Writing groups associated to this user for grp in groups: fout . write ("\\t" + str (grp) + "\\") def processors (fout) : A function to add all the available processors to the ouptut file fout . write ("\ PROCESSORS: \ ") # Command to get all the available processors info os . system ("cat /proc/cpuinfo > cpuinfo. txt") try : f proc = open ("cpuinfo. txt", "r") except FileNotFoundError: print ("File is not present") lines = f proc. readlines () processors = temp dict = {} line in lines :if line == "\ ": processors . append (temp_dict) temp_dict = {} temp_line = line. strip () . split(":") if (temp_line [0] . strip () == "processor") : temp dict ["Processor"] = temp_line [1] . strip () if (temp_line [0] . strip () == "vendor_id") : temp_dict ["Vendor_id"] = temp_line [1] . strip() if (temp_line [0] . strip () == "model") : temp_dict ["Model"] = temp_line [1] . strip() if (temp_line [0] . strip () == "model name") : temp_dict [ "Model_name"] = temp_line [1] . strip () if (temp_line [0] . strip () == "cache size") : temp_dict ["Cache"] = temp_line [1] . strip () # Writing the processors info to the output file for processor in processors: for key, value in processor . items () : Fout . write (f" {key) : {value} \ ") fout . write ("\ ") services (fout) : A function to add all the services along with their status to the ouptut file fout . write ("\ SERVICES: \ ") fout . write ( "SERVICE STATUS \ ") # Linux Command to list all the services information os . system ("systemctl list-units -type=service > services. txt") # Writing the service information to output file try : f services = open ("services. txt", "r") except FileNotFoundError: print ("Services file is not present") line = f_services . readline () while (line !="\ ") : fout . write (line) line = f_services . readline () f_services . close () main () : # Create a new Output file fout = open ("output . txt", "a+") # Writing Machine name to the file fout . write ("\ MACHINE_NAME: " + str (platform. node () ) + "\ ") user_groups (fout) processors (fout) services (fout) # Closing the output file fout . close ()\f
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
