Python script to run a linux command


#1

from fabric import tasks
from fabric.api import run
from fabric.api import env
from fabric.network import disconnect_all
import os
import platform
import csv
import subprocess

env.hosts = [
‘10.0.0.7’,
‘10.0.0.6’
]

m=len(env.hosts)

def pro():
global ch
global y
global n
y=None
n=None
ch=None
#m=len(env.hosts)
#print m
res1= run(‘ifconfig’)

def main():
uts_dict = tasks.execute(pro)
disconnect_all()

if name == ‘main’:
main()

When I run the above code in terminal it asks for password for both ip’s(10.0.0.6,10.0.0.7)
After giving the password I get the output.
How can I run the the program so that it does not ask for password and I directly get the output in terminal?


#2

Just a heads up - the content and discussions in this forum mostly revolve around Meteor, Apollo, and their surrounding ecosystem (javascript, mongo, react, angular, etc.). While someone in this forum might be able to help you out with a Python question, you might have better luck asking your question on a Python specific forum.

Unless of course this is somehow a Meteor related question?


#3

Okay. Thanks hwillson