import sys,os,re,datetime,psem min_date=datetime.datetime(1,1,1,0,0,0); max_date=datetime.datetime(9999,12,31,23,59,59); n_logs=0; uid=os.getuid(); gid=os.getgid(); pid=os.getpid(); shell="/bin/ksh"; def compress_log(server, year, month, day, hour, type, log): global min_date global n_logs p=os.path.join(os.getcwd(),year,month,day) log_date=datetime.datetime(int(year),int(month),int(day)) if log_date < min_date: min_date = log_date n_logs += 1 if not os.path.isdir(p): try: os.makedirs(p,0750) os.chown(p,uid,gid) except OSError,e: if not os.path.isdir(p): raise(e) return(-1) cmd = 'bzip2 '+log+' && chown `id -un`:`id -gn` ' + log + '.bz2 && chmod 0640 '+ log + '.bz2 && if [ "$p" != "$CWD" ]; then mv ' + log + '.bz2' + ' ' + p + '; fi;' pid = psem.fork() if pid == 0: os.execl(shell,shell,'-c',cmd) elif pid == -1: s = os.system(shell + " -c '" + cmd + "'") if os.WEXITSTATUS(s) != 0: return( os.WEXITSTATUS(s) ) return(0);