-2

I am trying to pass variables to call method (subprocess) as below:

def check(number):
    nodes = ["10.0.0.1","10.0.0.2"]
    nr=number
    for node in nodes:
        output=call(["ssh","-F","/home/config","user@",_node,","some_command",_nr])
        print output

The error when this function "check" is called is below:

NameError: global name '_node' is not defined

Can you please help me?

Ardit
  • 1,522
  • 17
  • 23
  • 3
    Why are you passing in _node & _nr? Shouldn't you be passing in node & nr? – mikea May 09 '16 at 14:09
  • 1
    Your problem is a lot more fundamental than anything to do with `subprocess`. Start smaller: try building up the list that you intend to pass to `call`, and verify that that list looks the way you think it should look before proceeding. You'll find you probably need to learn a few things about working with strings (maybe look for tutorials on concatenating and formatting strings in Python).\ – jez May 09 '16 at 14:14
  • 1
    `user@node` would have to be one argument, or use `"-u", user, node` to specify the user and remote host separately. – chepner May 09 '16 at 14:14

1 Answers1

3

You never define _node. You define node and nodes but never _node. I also don't see where you define _nr.

gr1zzly be4r
  • 2,072
  • 1
  • 18
  • 33