I tried with PYTHON to send cqlsh command via ssh and keep getting errors like
no viable alternative at input ':'
dsecqlsh.py not valid port
...
and I searched over internet including stack overflow, none gives the answer.
def sshRemoteCmd(user,host,cmd):
import subprocess
import re
x = subprocess.Popen("ssh {user}@{host} {cmd}".format(user=user, host=host, cmd=cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
result=''
if not x:
result = 'error'
else:
for item in x:
result += item.decode('ascii')
return result
cmd = f'''cqlsh -e "select * from MYTABLE where userid='12345';"'''
print(cmd)
result = sshRemoteCmd('root','hosts', cmd)
print(result)