In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
The source code of this article goes to: https://github.com/kasun/python-tail thanks the author, with a little modification, the function of dynamic upload of files is realized.
One: the main executive part, [root@linux219 base] # cat vsftp.pyrogen example, usrmax binmax env python#-*-coding:UTF-8-*- "" @ Item: cheetah v1.0@Author: william@Group: System YunWei@Date: 2015-01-28@E-mail: swq.499809608@163.com@Funtion: "import json,sys,time" Osimport timeimport hmacimport hashlibimport requestsimport reimport tailDfile = "/ data/base/vsftp" Vfile = "/ var/log/vsftpd.log" Nfile = "/ data/base/vsftp/n.log" def s3Vsftp (): os.system ("cp-fr% s% s"% (Vfile,Nfile)) os.system ("echo'>% s"% Vfile) fp = open (Nfile,'r'). Readlines () for x in fp: if re.search ("CHMOD") X) or re.search ("UPLOAD" X): X = x.strip () x = x.split ('") [3] nx = x.split () [0] if os.path.isfile (" / data/cifs "+ nx): os.system (" s3cmd-- acl-public put / data/cifs%s s3://swq499809608.aws.com%s "% (nx) Nx)) elif re.search ('zip',nx): try: os.system ("s3cmd-- acl-public put% s s3://swq499809608.aws.com%s"% (nx,nx.split (' imguser') [1]) except: pass os.system ("mv% s% s/%s.file"% (Nfile,Dfile) Time.strftime ("% F-%H-%M")) def work (): while True: t = tail.Tail (Vfile) print t.follow () if _ name__ = = "_ main__": sc = work () II: tail. Realize part of the source code to go to: https://github.com/kasun/python-tail[root@linux219 base] # cat tail.pyknoxpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # If no callback function is registerd, new lines would be printed to standard out. T.register_callback (callback_function) # Follow the file with 5 seconds as sleep time between iterations. # If sleep time is not provided 1 second is used as the default time. T.follow (object 5)'# Author-Kasun Herath # Source-https://github.com/kasun/python-tailimport osimport sysimport timeimport reclass Tail (object):''Represents a tail command. '' Def _ init__ (self, tailed_file):''Initiate a Tail instance. Check for file validity, assigns callback function to standard out. Arguments: tailed_file-File to be followed. '' Self.check_file_validity (tailed_file) self.tailed_file = tailed_file self.callback = sys.stdout.write def follow (self, slug 1):''Do a tail follow. If a callback function is registered it is called with every new line. Else printed to standard out. Arguments: s-Number of seconds to wait between each iteration; Defaults to 1. With open (self.tailed_file) as file_: # Go to the end of file file_.seek (0Magne2) while True: curr_position = file_.tell () line = file_.readline () if not line: file_.seek (curr_position) Time.sleep (s) else: # self.callback (line) if re.search ("CHMOD" Line) or re.search ("UPLOAD" Line): # modify the body x = line.strip () x = x.split ('"') [3] nx = x.split () [0] # commad s3cmd put file If os.path.isfile ("/ data/cifs" + nx): print "/ data/cifs" + nx os.system ("s3cmd-- acl-public put / data/cifs%s s3://swq499809608.aws.com%s"% (nx) Nx)) print ("s3cmd-- acl-public put / data/cifs%s s3://swq499809608.aws.com%s"% (nx,nx)) elif re.search ('zip' Nx): try: os.system ("s3cmd-- acl-public put% s s3://swq499809608.aws.com%s"% (nx Nx.split ('imguser') [1]) except: pass else: print' no' # body end part def register_callback (self, func):''Overrides default callback function to provided function. '' Self.callback = func def check_file_validity (self, file_):''Check whether the a given file exists, readable and is a file' if not os.access (file_, os.F_OK): raise TailError ("File'% s' does not exist"% (file_)) if not os.access (file_ Os.R_OK): raise TailError ("File'% s' not readable"% (file_)) if os.path.isdir (file_): raise TailError ("File'% s'is a directory"% (file_)) class TailError (Exception): def _ init__ (self, msg): self.message = msg def _ str__ (self): return 'yes' Self.message.split ('')
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
# check out the docker FileBond export PATH=$PATHif [$#-eq 1]; then docker history-- format {{. Cre
© 2024 shulou.com SLNews company. All rights reserved.