Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a script that reads a file periodically ( every 1 0 seconds ) . The file represents the command or commands that your script
Write a script that reads a file periodically every seconds
The file represents the command or commands that your script is to process in the background.
Every valid command in the file will begin with simon says:
The REMAINING part of the line is some text that needs to be appended to another destination file using echo external program.
If the line does not start with simon says output hackers and a list of current users to a separate file.
Apply the secure coding principles as needed. My answer is below. Let me know if it is correct please. import os
import time
import subprocess
def processcommandcommand:
if command.startswithsimon says:":
texttoappend commandlensimon says:":strip
appendtofiletexttoappend
else:
reporthackers
def appendtofiletext:
try:
with opendestinationfile.txta as destinationfile:
destinationfile.writetext
printCommand processed successfully."
except Exception as e:
printfError appending to destination file: e
def reporthackers:
try:
users subprocess.checkoutputwhodecodeutfstrip
with openhackersreport.txtw as reportfile:
reportfile.writehackers
reportfile.writeusers
printHacker report generated."
except Exception as e:
printfError generating hacker report: e
def main:
while True:
try:
with opencommandstxtr as commandsfile:
for line in commandsfile:
processcommandlinestrip
except Exception as e:
printfError reading commands file: e
time.sleep
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started