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

  • 相关阅读:
    [转]线程同步
    [转]C#线程同步(1)- 临界区&Lock
    获取系统空闲时间
    [转]一分钟明白 VS manifest 原理
    泛型总结
    wpf listbox touch 整个窗口移动
    git问题 next fetch will store in remotes/origin
    创建maven项目出现的问题
    JPA
    JDK JRE JVM
  • 原文地址:https://www.cnblogs.com/zhengchunyuan/p/7943976.html
Copyright © 2011-2022 走看看