在模块sh中使用变量

2024-05-16 20:27:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个脚本来显示服务器NIC的所有IP,但我有一个问题。你知道吗

如何在Python的sh模块中正确使用变量?你知道吗

我的代码示例:

allinterfaces = os.popen('/sbin/ifconfig -s |awk {\'print $1\'} |grep -v Iface')#.read().strip()

for interface in allinterfaces:
   print interface
   print sh.grep(sh.ifconfig('eth0'), "-oP", "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}")

我的问题是:如何更改变量的“eth0”?你知道吗


Tags: 模块代码ip服务器脚本示例ossh