我有下面的脚本,我不能让它搜索字符串然后输出值
如何获取参数并将其拆分,以便搜索“endpoint machine name=”,然后输出其值
命令如下:
python -u HostnameScript.py "discover-repository-location=null, Employee Notified=null, Manager Title=Exec Dir Biostatistics, date-detected=Mon Aug 25 16:03:35 PDT 2014, endpoint-machine-name=Davidpc, incident-id=603, sender-ip=null, Machine Name=null, Assigned To=null, Business Unit=Development US"
我试过将其拆分,但无法正确搜索
import sys, socket, string, commands, os, re, subprocess
arguments=sys.argv[1:]
for args in [item.split(", ") for item in arguments[]:
if item.find("endpoint-machine-name=") != -1
value=item.strip("endpoint-machine-name=")
sys.stdout.write('Hostname=');print value
我最后得到的只是
Hostname=discover-repository-location=null, Employee Notified=null, Manager Title=Exec Dir Biostatistics, date-detected=Mon Aug 25 16:03:35 PDT 2014, endpoint-machine-name=Davidpc, incident-id=603, sender-ip=null, Machine Name=null, Assigned To=null, Business Unit=Development US
像这样的怎么样
…或者,如果您真的想分析这些对:
当然,如果字符串
', '
出现在数据库中的任何位置,您都会遇到问题 价值观。而且,strip
也不是这样工作的strip
将字符串作为参数,该参数表示 应该从字符串中剥离,而不是特定的有序序列 角色如您所述,如果您需要使用其他脚本中的功能,请将其设置为独立的功能:
谢谢你的帮助。。我当然是在你的帮助下弄明白的
这是我使用的代码
相关问题 更多 >
编程相关推荐