V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2015-10-05 10:51:02 +08:00 · 3185 次点击
    这是一个创建于 3116 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    求大神帮忙。。。

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

    用 tail -f /var/log/wtmp | awk ... | custom_command 应该也可以.
    Aliencn
        6
    Aliencn  
       2015-10-05 19:42:05 +08:00
    “邮件内容包含登录者使用的用户名, IP 地址和登录时长。”
    系统自带的 last 命令搞定
    omph
        8
    omph  
       2015-10-06 10:44:11 +08:00
    @Zzzzzzzzz
    #file /var/log/wtmp
    /var/log/wtmp: FoxPro FPT, blocks size 0
    ---------------
    不过 python 有 DBF 模块可以解析
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3741 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 04:38 · PVG 12:38 · LAX 21:38 · JFK 00:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.