August 5th, 2005, 03:04 PM
Putting a variable into a system command
I am still slowly but surely plowing through my Quick Python book....
I have a list continaing ip addresses called ongoing.
for each value of of x in ongoing I want to create an iptable rule to reject said ip address. I think I am doing something stupid with quotes, I am not sure where they would go, or if I would have to use getattr with this:
for x in ongoing:
commands.getstatusoutput('iptables -A INPUT -p all -s x -d all -j REJECT')
how do I get the value of x to actually kick out into a shell command?
August 5th, 2005, 03:18 PM
commands.getstatusoutput("iptables -A INPUT -p all -s %s -d all -j REJECT" % x)