• 自动解压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

  • 相关阅读:
    ie的bug及兼容性
    解决多次include后全局变量global失效的问题
    针对MYISAM表锁的解决方案(转)
    解决二进制文件冲突
    linux基本命令(1) 开关机操作
    子网掩码(NETMASK),ip地址,默认网关
    linux中常见设备对照表
    解决base64通过http传输后+变空格的问题
    mysql 查询某值是否存在于某结果集或表中
    laravel 报错 No query results for model
  • 原文地址:https://www.cnblogs.com/zhengchunyuan/p/7943976.html
Copyright © 2020-2023  润新知