推荐学习书目
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 · 3889 views
    This topic created in 3952 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
        1
    mkeith  
       Oct 5, 2015
    基本定时读取系统日志文件
    oott123
        2
    oott123  
       Oct 5, 2015
    登录的话写到 /etc/profile 里应该可以
    登出没思路
    hsyu53
        4
    hsyu53  
       Oct 5, 2015
    登出的话,研究下 /etc/skel/.bash_logout 文件,这样对以后创建的每个用户都起作用。
    Zzzzzzzzz
        5
    Zzzzzzzzz  
       Oct 5, 2015
    inotify 监控 /var/log/wtmp

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