How do I use b
value in remote_conn.send
?
import paramiko
import time
import datetime
a=datetime.datetime.now() - datetime.timedelta(minutes=15)
b= a.strftime("%y-%m-%d.%H:%M:%S")
print b
def disable_paging(remote_conn):
'''Disable paging on a Cisco router'''
remote_conn.send("terminal length 0\n")
time.sleep(1)
# Clear the buffer on the screen
output = remote_conn.recv(1000000)
return output
AMGW28='/home/SIVA/843cc/MGW28aaa.txt'
MGW28='10.145.96.172'
if __name__ == '__main__':
def AMG(HOST,filenametoSave):
# VARIABLES THAT NEED CHANGED
ip = 'HOST`'
username = 'root'
password = 'Encrypt@25login'
# Create instance of SSHClient object
remote_conn_pre = paramiko.SSHClient()
# Automatically add untrusted hosts (make sure okay for security policy in your environment)
remote_conn_pre.set_missing_host_key_policy(
paramiko.AutoAddPolicy())
# initiate SSH connection
remote_conn_pre.connect(HOST, username=username, password=password)
print "SSH connection established to %s" % ip
# Use invoke_shell to establish an 'interactive session'
remote_conn = remote_conn_pre.invoke_shell()
print "Interactive SSH session established"
# Strip the initial router prompt
#output = remote_conn.recv(1000)
# See what we have
#print output
# Turn off paging
#disable_paging(remote_conn)
# Now let's try to send the router a command
a=datetime.datetime.now() - datetime.timedelta(minutes=15)
b= a.strftime("%y-%m-%d.%H:%M:%S")
print b
remote_conn.send("fsclish -c ' show alarm history filter-by specific-problem 70157 from-event-time %b ' \n")
# Wait for the command to complete
time.sleep(1)
output = remote_conn.recv(5000000)
print output
f=open(filenametoSave,'a+')
f.write(output)
f.close()
AMG(MGW28,AMGW28)