in Education by
I have a fixed list of services in a Linux server. I want to check the status of these services and start the service if it's stopped. I'm able to get this done using a shell script, but I'm looking for a Python script to do this. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can use python subprocess.Popen or os.system. Example: subprocess.Popen(["sudo", "service", "redis", "start"]) subprocess.Popen(["sudo", "service", "redis", "status"], stdout=subprocess.PIPE) You can read the stdout and check if the process is stopped and also see the exist status. Alternatively you can use psutil to monitor processes.

Related questions

0 votes
    I have a pdf template file that contains one form field. I want to fill out and flatten this form ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    How to check which Python version is interpreting my script? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I want to test a 2x2 matrix of [[5,6],[7,8]] to see if it's a square. I run ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    How can I remove emojis that start with '\x' when reading a csv file using pandas in Python? The ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me how do I start learning Python for Data Science? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me how to start a career in Python? Select the correct answer from above options...
asked Jan 8, 2022 in Education by JackTerrance
0 votes
    I want to run a python script from a shell script. I have been able to run it from the "command ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 26, 2022 in Education by JackTerrance
0 votes
    I want to run a python script from a shell script. I have been able to run it from the "command ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    I am aware of the die() command in PHP which stops a script early. How can I do this in Python? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I want to execute a curl command in python. curl -d @request.json --header "Content-Type: application/json" https: ... Help me fix it. Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    I am trying to write my below pinging script results into the Text file, but I am getting an error message. ... object is not iterable Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    I am writing a Python script in Windows. I want to do something based on the file size. For example, if the ... I check the file size? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    How can I check a given object is of a given type? How can I check that a object inherit a given type? There's ... that it's a string? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    What is the best way to open a file as reading/write if it exists, or if it does not, then create it and ... to do the opening part. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    suppose I have passed : list=[] How can I check if a list is empty or not? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
...