-1

how to run the following command in python script?

echo "show stat" | socat unix-connect:/var/run/haproxy/admin.sock stdio | grep webservers,BACKEND | cut -d , -f8

I tried this

import subprocess
var = subprocess.check_output(echo "show stat" | socat unix-connect:/var/run/haproxy/admin.sock stdio '| grep ' webservers,BACKEND' | cut -d , -f8', shell=True)
var=int(var)

but That doesn't work !

Adam
  • 159
  • 2
  • 5
  • 12

1 Answers1

0

Try with Popen :

from subprocess import Popen, PIPE

p1 = Popen(["echo", "show stat"], stdout=PIPE)
p2 = Popen(["socat", "unix-connect:/var/run/haproxy/admin.sock", "stdio"], stdin=p1.stdout)
p3 = Popen(["grep", "webservers,BACKEND"], stdin=p2.stdout)
p4 = Popen(["cut", "-d", ",", "-f8"], stdin=p3.stdout)
SLePort
  • 15,211
  • 3
  • 34
  • 44