Dear Sirs,
Good Day
Need help with the below code. Thanks in advance
Need a for loop here to run the below code on each of the IP Address provided in a file by a name file1 which has a list of IP Addresses separated by a new line. Instead of the IP address "10.137.111.31" mentioned below a variable needs to be put which substitutes its value (IP address) during each and every iteration of the for loop where in its value i.e. IP Address changes as stated in the file name file1 separated by a new line.
Good Day
Need help with the below code. Thanks in advance
Need a for loop here to run the below code on each of the IP Address provided in a file by a name file1 which has a list of IP Addresses separated by a new line. Instead of the IP address "10.137.111.31" mentioned below a variable needs to be put which substitutes its value (IP address) during each and every iteration of the for loop where in its value i.e. IP Address changes as stated in the file name file1 separated by a new line.
#!/usr/bin/python2 import pexpect # Need a for loop here to run the below code on each of the IP Address provided in a file by a name file1 which has a list of IP Addresses separated by a new line. Instead of the IP address "10.137.111.31" mentioned below a variable needs to be put which substitutes its value (IP address) during each and every iteration of the for loop where in its value i.e. IP Address changes as stated in the file name file1 separated by a new line. #Open connection and login. maintain the session output in /tmp/out child = pexpect.spawn('ssh [email protected]') child.logfile = open("/tmp/out", "a") child.expect('password:') child.sendline('Password1') #Wait for prompt and run command child.expect(".*\$ ") child.sendline('hostname') #Wait for prompt and run command child.expect(".*\$ ") child.sendline('uname -a') #Wait for prompt and run command child.expect(".*\$ ") child.sendline('date') #Logout child.expect('e025711.*') child.sendline('exit')