Python SSH problem

Hello geeks,

Am trying to write a custom plugin using python but it seems python is not handling the SSH part well, find below for the code:


#!/usr/bin/python
import os, sys

host = sys.argv[1]

pdpactgsm=os.popen("ssh -l GbeAdi $host "pdc_kpi.pl" | grep -A 4 sgsn_g | awk 'NR == 5 ' | awk '{print $4}' | sed 's/[^0-9,.]*//g'").readline().strip()

Python keeps pointing to the double quotes.

I have tried single quote but the command is not been passed to SSH correctly.

I know there are some Python SSH libraries but they seem not to have what I need or too deep to handle and time is not on my side.

You are nesting quotes which doesn't work.
Escape the inside quotes thus:

pdpactgsm=os.popen("ssh -l GbeAdi $host \"pdc_kpi.pl\" | grep -A 4 sgsn_g | awk 'NR == 5 ' | awk '{print $4}' | sed 's/[^0-9,.]*//g'").readline().strip()

Or just leave off the inside quotes:

pdpactgsm=os.popen("ssh -l GbeAdi $host pdc_kpi.pl | grep -A 4 sgsn_g | awk 'NR == 5 ' | awk '{print $4}' | sed 's/[^0-9,.]*//g'").readline().strip()