Having a list from a MySQL query, from my remote machine using a python script, I would like to put the results of the query into a txt file.
I am trying with this:
import subprocess
import sys
from subprocess import check_output
command = 'sshpass -p pass ssh user@ipaddress "echo \'' + str(list) + '\' > file.txt; ls"'
output = check_output(command, shell=True)
print (output)
But it returns an error.
Is there an easier way to do that?
The error:
File "ipcompare.py", line 53, in <module>
output3 = check_output(command, shell=True)
File "/usr/lib/python2.7/subprocess.py", line 223, in check_output
raise CalledProcessError(retcode, cmd, output=output)
An example of the list:
'['11.111.1.111/29-Name=0', '12.122.2.222/29-Name=0']