rsyslog.conf Configuring custom templates
$template Ssolog, "%msg%\n"
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
Writing scripts
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 + ' \ n ')
If File_path.endswith ('. zip '):
Extract_zip (Ftp_user, File_path)
Fh.write ('%s extract ok.\n '% file_path)
Elif file_path.endswith (' tar.gz '):
Extract_targz (Ftp_user, File_path)
Fh.write ('%s extract ok.\n '% file_path)
Elif File_path.endswith ('. tgz '):
Extract_tgz (Ftp_user, File_path)
Fh.write ('%s extract ok.\n '% file_path)
Else
Pass
Fh.close ()
Automatic decompression of vsftpd uploaded files