Python Web 版本tailf, grep

Python有一个插件,可以让我们在网页上实现类似于Linux 下tailf, grep和awk的功能。这个插件的名字是tailon。

安装插件,

pip install tailon

 启动服务:

tailon -f /var/log/nginx/* /var/log/apache/{access,error}.log

 服务如果正常启动就可以在浏览器里使用:http://localhost:8080 访问。

 更多命令:

Usage: tailon [-c path] [-f path [path ...]] [-h] [-d] [-v]
              [--output-encoding enc] [--input-encoding enc] [-b addr:port]
              [-r path] [-p type] [-u user:pass] [-a] [-f] [-t num]
              [-m [cmd [cmd ...]]] [--no-wrap-lines]

Tailon is a web app for looking at and searching through log files.

Required options:
  -c, --config path               yaml config file
  -f, --files path [path ...]     list of files or file wildcards to expose

General options:
  -h, --help                      show this help message and exit
  -d, --debug                     show debug messages
  -v, --version                   show program's version number and exit
  --output-encoding enc           encoding for output
  --input-encoding enc            encoding for input and output (default utf8)

Server options:
  -b, --bind addr:port            listen on the specified address and port
  -r, --relative-root path        web app root path
  -p, --http-auth type            enable http authentication (digest or basic)
  -u, --user user:pass            http authentication username and password
  -a, --allow-transfers           allow log file downloads
  -F, --follow-names              allow tailing of not-yet-existent files
  -t, --tail-lines num            number of lines to tail initially
  -m, --commands [cmd [cmd ...]]  allowed commands (default: tail grep awk)

User-interface options:
  --no-wrap-lines                 initial line-wrapping state (default: true)

Example config file:
  bind: 0.0.0.0:8080      # address and port to bind on
  allow-transfers: true   # allow log file downloads
  follow-names: false     # allow tailing of not-yet-existent files
  relative-root: /tailon  # web app root path (default: '')
  commands: [tail, grep]  # allowed commands
  tail-lines: 10          # number of lines to tail initially
  wrap-lines: true        # initial line-wrapping state

  files:
    - '/var/log/messages'
    - '/var/log/nginx/*.log'
    - '/var/log/xorg.[0-10].log'
    - '/var/log/nginx/'   # all files in this directory
    - 'cron':             # it's possible to add sub-sections
        - '/var/log/cron*'

  http-auth: basic        # enable authentication (optional)
  users:                  # password access (optional)
    user1: pass1

Example command-line:
  tailon -f /var/log/messages /var/log/debug -m tail
  tailon -f '/var/log/cron*' -a -b localhost:8080
  tailon -f /var/log/ -p basic -u user1:pass1 -u user2:pass2
  tailon -c config.yaml -d

 

转载于:https://www.cnblogs.com/diaolanshan/p/9270646.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Python grep是一种基于Python编程语言的文本搜索工具,它可以在文本文件中查找指定的字符串,并将匹配的行输出到屏幕或文件中。Python grep可以使用正则表达式进行高级搜索,支持多种搜索模式和选项,是一种非常强大和灵活的文本搜索工具。 ### 回答2: Python grep 是一种基于 Python 编程语言开发的文本搜索工具,用于在文件或输入中查找并提取满足特定模式的文本行。 Python grep 使用正则表达式作为搜索模式,可以灵活地指定要搜索的文本规则。它可以在一个或多个文件、文件夹、目录树或标准输入中搜索匹配的文本,并返回相应的结果。 Python grep 提供了各种选项和参数,可以根据需求指定搜索的深度、忽略大小写、显示行号、只显示匹配的行等。它还可以与其他命令行工具连接使用,例如通过管道将输出传递给其他命令或将多个结果合并。 Python grep 还具有强大的扩展性,可以根据需要自定义搜索功能。通过编写自己的脚本或使用现有的 Python 模块,可以实现更复杂的搜索操作,如搜索多个模式、自定义过滤条件、对搜索结果进行处理等。 总之,Python grep 提供了一种方便且强大的文本搜索工具。它使用简单,具有灵活性和扩展性,可以满足各种文本搜索需求。无论是在开发阶段调试代码,还是在处理大量文本数据时,Python grep 都是一个有用的工具。 ### 回答3: Python中的grep是一种用于在文本中进行模式匹配和搜索的工具。它可以帮助我们快速定位并筛选出符合特定模式的文本行。 在Python中,我们可以使用re模块(正则表达式)来实现类似于grep的功能。re模块提供了一个函数re.search(pattern, string)来搜索满足正则表达式pattern的字符串string。如果匹配成功,则返回一个匹配对象;否则返回None。 下面是一个简单的示例,演示了如何使用Pythongrep来搜索包含特定关键词的文本行: ``` import re def grep(pattern, lines): for line in lines: if re.search(pattern, line): print(line) # 示例用法 lines = ["This is line 1", "This is line 2", "Another line"] pattern = "line" grep(pattern, lines) ``` 运行上述代码,将输出包含关键词"line"的文本行:"This is line 1"和"This is line 2"。 除了re.search函数外,re模块还提供了其他函数,如re.match和re.findall,它们也可以用于字符串的模式匹配和搜索。可以根据具体的需求选择适合的函数来实现类似于grep的功能。 总结起来,Python中的grep类似于在文本中进行模式匹配和搜索的工具,我们可以使用re模块中的函数来实现类似的功能。希望以上回答能对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值