My Linux script is as below to ssh to host & search patch update which has kernel update
for host in `cat patch.csv`
do
echo "Host $host" >> /tmp/patching
ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" $host 'sudo yum check-update | grep "kernel.x86"'>>/tmp/patching
done
Now i am trying to write a python script equivalent to this & its showing error(not able to conenct to ssh). I tried to use subprocess comamnd which is not working - its not able to pick up hostname & public key error.
import subprocess
import os
def read_file():
# Read and print the entire file line by line
with open('patch.csv', 'r') as reader:
with open('server_names.txt', 'w') as writer:
for host in reader:
writer.write(host)
p = subprocess.Popen(["ssh -o 'UserKnownHostsFile=/dev/null' -o 'StrictHostKeyChecking=no' host 'sudo yum check-update | grep kernel.x86'"], shell=True, stdout=subprocess.PIPE)
output, err = p.communicate()
print(host)
print("file read done")
read_file()