# Send Command to a linux host using workflows

**URL:** <https://community.dynatrace.com/t/send-command-to-a-linux-host-using-workflows/48769>\
**Category:** Automations\
**Tags:** linux, edgeconnect, workflows\
**Created:** [November 6, 2024, 4:55pm UTC](https://community.dynatrace.com/t/send-command-to-a-linux-host-using-workflows/48769 "2024-11-06T16:55:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorge3229](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@Jorge3229](https://community.dynatrace.com/u/Jorge3229)\
**Post date:** [November 6, 2024, 4:55pm UTC](https://community.dynatrace.com/t/send-command-to-a-linux-host-using-workflows/48769/1 "2024-11-06T16:55:25Z")

</div>

Good day everyone, I am currently working with EdgeConnect because I want to send commands to a Linux host to restart a process. I remember seeing an EdgeConnect application for workflows, is that correct?

If that app no longer exists, how can I send that command to my host through a workflow?

---

<div class="post-metadata">

**Author:** ![DanielS](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@DanielS](https://community.dynatrace.com/u/DanielS)\
**Post date:** [November 7, 2024, 3:19am UTC](https://community.dynatrace.com/t/send-command-to-a-linux-host-using-workflows/48769/2 "2024-11-07T03:19:53Z")

</div>

Hello&nbsp;[@Jorge3229](https://community.dynatrace.com/user/58775)&nbsp;using ansible does the trick.

[https://xxxxxxxx.apps.dynatrace.com/ui/apps/dynatrace.hub/browse/all?search=ansible&details=dynatrace.redhat.ansible](https://xxxxxxxx.apps.dynatrace.com/ui/apps/dynatrace.hub/browse/all?search=ansible&details=dynatrace.redhat.ansible)

with this you can create an action to launch a job template in Red Hat Ansible Automation Controller.

---

<div class="post-metadata">

**Author:** ![christian\_kreuz](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/christian_kreuz/32/21669_2.png) [@christian\_kreuz](https://community.dynatrace.com/u/christian_kreuz)\
**Post date:** [November 15, 2024, 8:44am UTC](https://community.dynatrace.com/t/send-command-to-a-linux-host-using-workflows/48769/3 "2024-11-15T08:44:15Z")

</div>

You can take a look at Kubernetes Automation: [Kubernetes Connector — Dynatrace Docs](https://docs.dynatrace.com/docs/platform-modules/automations/workflows/actions/kubernetes-automation)

This leverages EdgeConnect on Kubernetes, and you can leverage [several actions](https://docs.dynatrace.com/docs/platform-modules/automations/workflows/actions/kubernetes-automation/kubernetes-workflow-actions) (e.g., apply configuration or restart deployment) to perform certain tasks.

In theory you can also try to use a Kubernetes job/workload to execute a command on another host.

Please also refer to [@DanielS](https://community.dynatrace.com/user/35788) post about using Red Hat Ansible, that’s a perfect alternative.

---

<div class="post-metadata">

**Author:** ![PacoPorro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pacoporro/32/36087_2.png) [@PacoPorro](https://community.dynatrace.com/u/PacoPorro)\
**Post date:** [November 15, 2024, 9:32am UTC](https://community.dynatrace.com/t/send-command-to-a-linux-host-using-workflows/48769/4 "2024-11-15T09:32:22Z")

</div>

You can use a server in your host to allow restarting the process.  
I do prefer the Ansible solution as it is more scalable than this approach.  
But something like this should work.

```python
import ssl
from http.server import HTTPServer, BaseHTTPRequestHandler
import subprocess

class RequestHandler(BaseHTTPRequestHandler):
    def do_POST(self):
        if self.path == '/restart-process':
            # Add authentication check here if needed
            self.restart_process()
        else:
            self.send_error(404, "Not Found")

    def restart_process(self):
        try:
            # Replace this with your actual restart command
            subprocess.run(["systemctl", "restart", "your-process-name"], check=True)
            self.send_response(200)
            self.send_header('Content-type', 'text/plain')
            self.end_headers()
            self.wfile.write(b"Process restarted successfully")
        except subprocess.CalledProcessError:
            self.send_error(500, "Failed to restart process")

def run_server():
    server_address = ('your-linux-host.internal', 443) # Use the appropriate hostname and port
    httpd = HTTPServer(server_address, RequestHandler)

    # SSL wrapping
    context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
    context.load_cert_chain('server.crt', 'server.key')
    httpd.socket = context.wrap_socket(httpd.socket, server_side=True)

    print(f"Server running on https://{server_address[0]}:{server_address[1]}")
    httpd.serve_forever()

if __name__ == ' __main__':
    run_server()

```

server.crt&nbsp;and&nbsp;server.key&nbsp;used for HTTPS  
&nbsp;The&nbsp;restart\_process&nbsp;method uses&nbsp;subprocess.run&nbsp;to execute the restart command. Replace&nbsp;“your-process-name”&nbsp;with the actual process name
