Mar-20-2018, 11:55 AM
Hi All,
My first ssh script to collect output, output file is almost 100000 lines, its runing ok through prompt however
while runing through crontab, its creating multiple processes.
contrab entry
My first ssh script to collect output, output file is almost 100000 lines, its runing ok through prompt however
while runing through crontab, its creating multiple processes.
contrab entry
Quote:/bin/sh -c (cd /home/anna/scripts/; /usr/bin/python /home/anna/scripts/bulkdn.py >/dev/null 2>&1)
import paramiko
import time
import re
import os
def disable_paging(remote_conn):
remote_conn.send("environment no more\n")
time.sleep(1)
# Clear the buffer on the screen
output = remote_conn.recv(1000)
return output
if __name__ == '__main__':
# VARIABLES THAT NEED CHANGED
ip = '10.14.17.138'
username = 'anna'
password = 'test123'
# 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(ip, username=username, password=password, look_for_keys=False, allow_agent=False)
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"
# Turn off paging
disable_paging(remote_conn)
# Now let's try to send the router a command
remote_conn.send("\n")
remote_conn.send("environment no more\n")
#remote_conn.send("show version\n")
remote_conn.send("show service id 1 ppp session \n")
# Wait for the command to complete
finalOutput = " "
time.sleep(10)
while True:
output = remote_conn.recv(500)
if "sessions:" in output:
break
else:
finalOutput += output
file = open('/home/anna/scripts/bulkdn.txt','w')
file.write(finalOutput)
file.close()is there any issue in script?
