'Make a single SSH connection via paramiko and send a command to check the hostname and a 2nd command to see if there is anything in the www directory

Your manager just asked you to find out what is the hostname (/etc/hostname) and if there are any files in the www directory. Your manager wants you to check this on two Ubuntu-based machines. However, they want you to have this written in a way that will scale to all 100 servers on the network. Achieve the following items:

Make a Flowchart.

Create Pseudocode.

Make a single SSH connection via paramiko and send a command to check the hostname and a second command to see if there is anything in the www directory.

Input the IP addresses from a file (text or CSV).

Save the output of both commands, make sure to note what IP the data came from, to a file (text or CSV).



Solution 1:[1]

As mirlinda said, this is a set of requirement rather than a question. I just have a plan for your information.

  1. You can write all ip address to text file with one ip per line.
  2. Use ssh-keygen -t rsa -C "your mail" command to create ssh rsa key in your 100 servers.
  3. Run ssh-copy-id -i ~/.ssh/id_rsa.pub root@[ip] to make your administrator machine can access which server you want to access without password.
  4. Write a python script to read one ip per time from the text file saved your all server ip by readline interface.
  5. And use check_output interface to run hostname command to get server host name and ls [full path of www] to get contents of www directory.
  6. You just can save return contents of check_output interface to a file by redirection symbol '>'.
  7. Loop operations 4-6 in your python script by using while or for statement until get all host name and contents of www of all 100 servers.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yayong Duan