0

I am new to python, looking to write a script which would ssh to about 1000 hosts from a jump server and Output should contain the hostname and version of the operating system. Redhat 5.0 or 6,0 etc and I have list of all the hosts and so the script can keep getting hostname from the hosts list. Is it possible using paramiko and platform modules ??.. I would really appreciate if someone could give a rough frame for getting me started. or similar script.

Brendan Abel
  • 35,343
  • 14
  • 88
  • 118
Gana Sagar
  • 131
  • 2
  • 13

2 Answers2

0

The socket and platform can do this.

import socket
import platform

print socket.gethostname()
print platform.platform()
Brendan Abel
  • 35,343
  • 14
  • 88
  • 118
  • thank you for the reply, I have done all of the above already. The challenge I am facing is, how do I append each server's output to my jump server's log file. SSH is not possible because we have only way we login to any server is via JUMP server for security measures not the otherway around. How do i gather the output of various servers ? – Gana Sagar Apr 12 '16 at 20:50
0

You can use a combination of paramiko and shell commands. See

Perform commands over ssh with Python

ssh = paramiko.SSHClient()
ssh.connect(server, username=username, password=password)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd_to_execute)

Here, for cmd_to_execute you can use 'hostname':

http://linux.die.net/man/1/hostname

and to find the Redhat version

$cat /etc/redhat-release

See: https://unix.stackexchange.com/questions/88644/how-to-check-os-and-version-using-a-linux-command

Community
  • 1
  • 1
trans1st0r
  • 2,023
  • 2
  • 17
  • 23
  • thank you for the reply, I have done all of the above already. The challenge I am facing is, how do I append each server's output to my jump server's log file. SSH is not possible because we have only way we login to any server is via JUMP server for security measures not the otherway around. How do i gather the output of various servers ? – Gana Sagar Apr 12 '16 at 20:46
  • I can still see the output from the script on my CLI after the execution. Is there anyway to redirect the output to log file instead of displaying on the screen. – Gana Sagar Apr 12 '16 at 20:56