Python Scripting For Storage Admin Part 7 Login To Multiple Server And Run Command

preview_player
Показать описание
Support Us By Shopping Your Own Favorite Products
#PythonScriptingForStorageAdmin #StorageAutomation
Python: Programming Basics for Absolute Beginners
In this script, we will write python code which will log in to multiple Unix servers and execute a command. After that whatever output that command will give the script will save in a text file.


Overview of Python Script
1. Read credentials from CSV file
2. log in to multiple devices one by one
3. Execute command
4. Save the output in a txt file

Below is the script written in python which will log in to multiple devices and execute commands.
The below line will import a module called paramiko which is used for ssh connectivity to the Unix server.

import paramiko

The below line will initiate an object for ssh connectivity.

p = paramiko.SSHClient()

The below line will open a credential file in a reading mode where we have credentials for the devices.

Now below is the for loop which will iterate over each line of the file and get the credential, login to the device, and execute a command. Then the output of the command for each device will be saved in a text file.

print(ls)
opt ="".join(opt)
print(opt)
Рекомендации по теме
Комментарии
Автор

Thanks for video and it is really helpful.. Please post more video with different example. And also please explain what is API and how we can use those

manikandang
Автор

Thanks a lot for your videos as it gave a good start for me in Python.
Could you please tell me the need of the line "p.set_missing_host_key_policy", what will happen if we are not using that?

anish
Автор

As I am executing the code, getting below error

return codecs.charmap_decode(input, self.errors, decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 16: character maps to <undefined>

Any suggestion on this error code

AshishSharma-fqez
Автор

Hello sir thabks for this video
Could you please make a video to fetch some information from multiple linux servers in excel file with some formatting like color value when exceeding threshold value ???

mkamran
Автор

Thanks.. Very useful script.
Please continue more videos

syedsaifulla
Автор

Sir, how we can import paramiko in python script.. We need to download any file or is there any seperate program..Can you please teach me

narmathaselvaraj
Автор

Thank you very much, Its very helpful script, Please add few more videos like this kind of

gangulyreddy
Автор

Thanks for the script sir. Instead multiple. txt output files i want single .csv file with hostname or ip included in it. Can u help me sir?

nikhilkadam
Автор

Hi, thank you so much for this such a nice session, Could you please provide and script to execute multiple cmds in multiple server in single scripts. Thank you again...

PANKAJKUMAR-rhys
Автор

Using python, ssh to server and server name and kernel version and provide output in json format
Please help me

rishabhshukla
Автор

can you tell me what should i do if i want to run 1st command then analyse the output and then run another command.

ravinderyadav
Автор

Thanks lot for your video,
Could you please tell me how to execute multiple commands in that script.

alvins
Автор

Sir, waiting for your more modules.... even my many friends... please upload..

powerstar
Автор

Do you have a procedure or sample code to do parallel ssh to multiple nodes at the same time?

harikumarmanickam
Автор

I want to login to a linux server first as admin mode, after that i want to login as a root (log root is the command) from admin mode. (Direct login root is not supported)
How can i solve my problem?

gowthamappy
Автор

same script I need to use for below senario.
1st Command
Commands # seccertutil genkey
Promt to enter # Yes or NO : yes
Key size : 2048
2nd Command
Commands # seccertutil gencsr -country Sg -state PRD -localcity
Prompt to enter # sha256
Prompt to enter file name # Switch1.csr

After key generate, Need to download.
Command # Seccertutil export
Prompt ftp or scp # scp
Prompt for IP # 10.10.10.10
path to save : /
login : admin
password : 12345678

Then our file will save..
But am failing since above script prompt give value and yes or now then agian save the files in server.
can you help please.

powerstar
Автор

Hi sir, thanks for video, I have one doubt, what happens if one of the IP in *.csv file is not reachable?

aravinds
Автор

Thanks you so much, I have one qs, while I am able to connect the storage device after unable to execute the command, could u pls help me.

merasafaraapsabkesaath
Автор

How to get all device output in single file

visalakshil
Автор

I see while executing the same cod. How to resolve that?

ThePasupathi
join shbcf.ru