1

我一直在寻找解决方案,但我所看到的没有一个与我的问题相同。我正在使用带有运行命令的结构来远程运行 hostname -i 。所以这就是我所拥有的:

ip = run("hostname -i")
if %s in run("nodetool -h localhost ring | awk '{ print $1}' | grep `hostname -i`") % ip:
        print(green("The host is in the ring"))

我只是想检查在运行 nodetool 命令时是否显示了当前服务器的 IP 地址。不是如何做到这一点。我是 python 新手。

所以我试图为变量分配一个“ip”,但出现了一个引发问题的错误:

>>> ip = 10.0.0.1
  File "<stdin>", line 1
    ip = 10.0.0.1
              ^
SyntaxError: invalid syntax

编辑:

I tried a few things and this seems to work:

>>> ip = local("hostname -i")
[localhost] local: hostname -i
10.88.17.59
>>> if ip > 1:
...     print "yes"
... else:
...     print "no"
... 
yes
>>> if ip in local("hostname -i"):
...     print "yes"
... else:
...     print "no"
... 
[localhost] local: hostname -i
10.88.17.59
yes
4

1 回答 1

-1

我尝试了一些事情,这似乎有效:

>>> ip = local("hostname -i")
[localhost] local: hostname -i
10.1.2.3
>>> if ip > 1:
...     print "yes"
... else:
...     print "no"
... 
yes
>>> if ip in local("hostname -i"):
...     print "yes"
... else:
...     print "no"
... 
[localhost] local: hostname -i
10.1.2.3
yes
于 2013-06-19T19:05:54.473 回答