推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
uxstone
V2EX  ›  Python

求一段 Python 脚本, ubuntu 系统相关。

  •  
  •   uxstone · Oct 5, 2015 · 4043 views
    This topic created in 4068 days ago, the information mentioned may be changed or developed.

    实现功能:
    当有系统用户登录或退出 ubuntu 服务器时,
    python 脚本就自动发送邮件到指定邮箱。
    邮件内容包含登录者使用的用户名, IP 地址和登录时长。
    python 能在系统开机后就一直监控系统的用户登录情况。

    目前发送邮件的脚本写好了,
    而怎么在系统开机就一直监控并且用户登录退出就自动发送邮件,不会弄。

    求大神帮忙。。。

    8 replies  •  2015-10-06 10:44:11 +08:00
    mkeith
    mkeith
    Oct 5, 2015
    1
    基本定时读取系统日志文件
    oott123
    oott123
    Oct 5, 2015
    2
    登录的话写到 /etc/profile 里应该可以
    登出没思路
    hsyu53
    hsyu53
    Oct 5, 2015
    4
    登出的话,研究下 /etc/skel/.bash_logout 文件,这样对以后创建的每个用户都起作用。
    Zzzzzzzzz
    Zzzzzzzzz
    Oct 5, 2015
    5
    inotify 监控 /var/log/wtmp

    用 tail -f /var/log/wtmp | awk ... | custom_command 应该也可以.
    Aliencn
    Aliencn
    Oct 5, 2015
    6
    “邮件内容包含登录者使用的用户名, IP 地址和登录时长。”
    系统自带的 last 命令搞定
    omph
    omph
    Oct 6, 2015
    8
    @Zzzzzzzzz
    #file /var/log/wtmp
    /var/log/wtmp: FoxPro FPT, blocks size 0
    ---------------
    不过 python 有 DBF 模块可以解析
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2205 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 56ms · UTC 14:33 · PVG 22:33 · LAX 06:33 · JFK 09:33
    ♥ Do have faith in what you're doing.