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 = 10.100.33.000
port=1234

serversocket.bind((host,port))

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

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.

Answer

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.