标签:split ftpd load zip vsftpd [1] auto pass root
rsyslog.conf配置自定义模板
$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
编写脚本
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()
标签:split ftpd load zip vsftpd [1] auto pass root
原文地址:http://www.cnblogs.com/zhengchunyuan/p/7943976.html