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

  • 相关阅读:
    机器学习笔记[保持更新]
    习题 7-3 uva211
    习题 7-2 uva225(回溯)
    习题7-1 uva 208(剪枝)
    poj2331 (IDA*)
    poj2449 (第k条最短路)
    POJ 1324(BFS + 状态压缩)
    hdu3567 八数码(搜索)--预处理
    poj 1367 robot(搜索)
    例 7-10 uva12212(迭代加深搜索)
  • 原文地址:https://www.cnblogs.com/zhengchunyuan/p/7943976.html
Copyright © 2011-2022 走看看