zoukankan      html  css  js  c++  java
  • 自动解压vsftpd上传的文件

    rsyslog.conf配置自定义模板

    $template ssolog,"%msg% "
    if $programname == 'vsftpd' then ^/bin/auto_unzip.py;ssolog
    #$ModLoad omprog
    #$ActionOMProgBinary /etc/auto_unzip.py
    #if $programname == 'vsftpd' then :omprog:;ssolog *.* /var/log/mvsftpd.log;ssolog

    编写脚本

    vim /bin/auto_unzip.py

    #!/usr/bin/python

    import sys
    import os


    BASE_DIR = '/home/wwwroot/default/client/'

    def extract_zip(ftp_user, file_path):
    abs_file_path = os.path.join(BASE_DIR, file_path[1:])
    if ftp_user != '':
    os.system('sudo unzip %s -d %s' % (abs_file_path, os.path.dirname(abs_file_path)))
    os.system('sudo chown %s.%s -R %s' % (ftp_user, ftp_user, os.path.dirname(abs_file_path)))
    os.system('sudo rm -f %s' % abs_file_path)
    else:
    return

    def extract_targz(ftp_user, file_path):
    abs_file_path = os.path.join(BASE_DIR, file_path[1:])
    if ftp_user != '':
    os.system('sudo tar zxf %s -C %s' % (abs_file_path, os.path.dirname(abs_file_path)))
    os.system('sudo chown %s.%s -R %s' % (ftp_user, ftp_user, os.path.dirname(abs_file_path)))
    os.system('sudo rm -f %s' % abs_file_path)
    else:
    return

    def extract_tgz(ftp_user, file_path):
    abs_file_path = os.path.join(BASE_DIR, file_path[1:])
    if ftp_user != '':
    os.system('sudo tar xf %s -C %s' % (abs_file_path, os.path.dirname(abs_file_path)))
    os.system('sudo chown %s.%s -R %s' % (ftp_user, ftp_user, os.path.dirname(abs_file_path)))
    os.system('sudo rm -f %s' % abs_file_path)
    else:
    return

    fh = open('/tmp/auto_unzip.log', 'a+')

    log = sys.argv[1]
    log_arr = log.split(',')
    if len(log_arr) > 2:
    ftp_user = ''
    ftp_user_arr = log_arr[0].split(' ')
    if len(ftp_user_arr) > 1:
    ftp_user = ftp_user_arr[1].strip('[] ')
    file_path = log_arr[1].strip('" ')
    #fh.write(file_path + ' ')
    if file_path.endswith('.zip'):
    extract_zip(ftp_user, file_path)
    fh.write('%s extract ok. ' % file_path)
    elif file_path.endswith('tar.gz'):
    extract_targz(ftp_user, file_path)
    fh.write('%s extract ok. ' % file_path)
    elif file_path.endswith('.tgz'):
    extract_tgz(ftp_user, file_path)
    fh.write('%s extract ok. ' % file_path)
    else:
    pass
    fh.close()

    rsyslog变量:http://www.rsyslog.com/doc/v8-stable/configuration/properties.html

    模板:http://www.rsyslog.com/doc/v8-stable/configuration/templates.html

  • 相关阅读:
    3、Semantic-UI之定义容器
    2、Semantic-UI之网格布局
    1、Semantic-UI之开发环境搭建
    PyCharm创建普通项目配置支持jinja2语法
    CentOS 7安装GitLab、汉化、配置邮件发送
    Docker swarm 实战-部署wordpress
    线程和进程
    NGINX内置变量
    iTerm2 + Oh My Zsh 打造舒适终端体验
    CentOS 7修改网卡名称
  • 原文地址:https://www.cnblogs.com/zhengchunyuan/p/7943976.html
Copyright © 2011-2022 走看看