Using shell = True
can be a security risk if your input data comes from an untrusted source. E.g. what if the content of your mid
variable is "/dev/null; rm -rf /"
. This does not seem to be the case in your scenario, so I would not worry too much about it.
In your code you write the result of awk
directly to the filename in mid
. To debug the problem, you might want to use subprocess.check_output
and read the result from your awk
invocation in your python program.
cmd = """sort -n -r -k5 %s |
head -n 500|
awk 'OFS="\t"{{if($2-{1}>0){{print $1,$2-{1},$3+{1},$4,$5}}}}'""".format(summit, top_count)
subprocess.check_call(cmd, shell=True, stdout=file)