I want to write a python script to ssh remote machines and run command netstat -antp | grep httpd
run this script in Cron job.
Here I'm grepping for httpd
service and check the port no (say 80). Only one of the remote machine can have 80 rest should have different port no like 8888 or 8080.
list of remote machine I want to take as argument while running the python script.
Below is my code snippet:
import subprocess
import sys
machine_list= sys.argv[1]
for machine in machine_list:
command = "sudo netstat -antp | grep httpd"
ssh = subprocess.Popen(["ssh", "%s" % machine, command],
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result = ssh.stdout.readlines()
Problem is everytime I run it asks me for password of remote machine. I cannot give password manually if running in cron. What can be done?