How to shutdown a database server with python script? [closed]

I wanted to shutdown a database server with python script. Here is the below code I know connecting and closing:

import socket

serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host =


while True:
    clientsocket, addr = serversocket.accept
    print('Got a connection from %s' % str(addr))
    msg = 'thank you' + 'rn'

The above is for connect and close.

But getting error “connection timeout”

How to shutdown and start a server with python script?

Thanks in advance.


You can login to the server and the script file should have the executable permission and make sure you have installed python in that server, upon that you can execute it there itself. Please refer run sh file with python os, this might be useful.