Python awk command -


import os import sys  os.system ('kill "$(ps aux | grep snmp | awk '"{print $2}"' | head -n1)"') 

i trying kill process in python, have error line:

awk: line 2: missing } near end of file sh: 1: kill: illegal number  

the problem comes awk command, don't know exact syntax. can me please?

thank in advance!

the ' around awk ' terminates python string, end concatenation of 'kill "$(ps aux | grep snmp | awk ', "{print $2}", , ' | head -n1)"', trying execute:

$ kill "$(ps aux | grep snmp | awk {print $2} | head -n1)" 

where { parsed shell syntax.

this should work:

os.system('kill "$(ps aux | grep snmp| awk \'{print $2}\' | head -n1)"') 

a possibly better approach use pkill:

os.system('pkill snmp') 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -