I am logging into a box and grep'ing a file content and printing to a file. I can print the grep'ed text but I am not able to print the host name to the file.
import paramiko
k = paramiko.RSAKey.from_private_key_file("/Users/Documents/privatekey.pem")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print ("connecting")
c.connect( hostname = "10.224.58.214", username = "ec2-user", pkey = k )
print ("connected")
commands = [ "grep jdbc /usr/share/activemq/conf/activemq.xml" ]
for command in commands:
#print ("Executing {0}".format( command ))
stdin , stdout, stderr = c.exec_command(command)
print (hostname,file=open("output.csv", "a"))
print (stdout.read(),file=open("output.csv", "a"))
#print("Errors")
#print (stderr.read())
c.close()
The line print (hostname,file=open("output.csv", "a")) is erroring out saying hostname is not defined.