#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    40
    Rep Power
    10

    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?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    Hi!

    Warning: untested
    Code:
    commands.getstatusoutput("iptables -A INPUT -p all -s %s -d all -j REJECT" % x)
    Regards, mawe

IMN logo majestic logo threadwatch logo seochat tools logo