/[web]/data/lib/Mageia/Data/Cron.php
ViewVC logotype

Contents of /data/lib/Mageia/Data/Cron.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1525 - (show annotations) (download)
Mon Jul 30 00:03:15 2012 UTC (8 years, 10 months ago) by rda
File size: 1774 byte(s)
add libraries
1 <?php
2
3 /**
4 */
5 abstract class Mageia_Data_Cron
6 {
7 function __construct($spec, $ts, $appdir, $logtmpdir)
8 {
9 $this->name = $spec[0];
10 $this->user = $spec[1];
11 $this->host = $spec[2];
12 $this->day_YMD = date('Y-m-d', $ts);
13 $this->day_AL = date('d/M/Y', $ts);
14 $this->appdir = $appdir;
15
16 $filename = sprintf('%s_%s.log', $this->host, $this->day_YMD);
17 $this->log_file = sprintf('%s/%s/%s', $this->appdir, $logtmpdir, $filename);
18
19 $this->clean_log_file = $this->log_file . '.clean';
20 $this->final_log = sprintf('%s/final/%s/%s', $this->appdir, $this->name, $filename);
21 }
22
23 public final function run()
24 {
25 $this->fetch_log();
26 $this->digest_log($this->log_file, $this->clean_log_file);
27 $this->move_log();
28 $this->cleanup();
29 }
30
31 private final function fetch_log()
32 {
33 $cmd = sprintf('ssh %s@%s grep "%s" /var/log/httpd/%s-access_log > %s',
34 $this->user,
35 $this->host,
36 $this->day_AL,
37 $this->host,
38 $this->log_file
39 );
40 echo sprintf("Grep logs on %s for %s on %s...\n", $this->host, $this->name, $this->day_AL);
41 exec($cmd, $out, $ret);
42 if ($ret > 0) {
43 die("Failed: $ret. Aborting.\n");
44 }
45 }
46
47 public abstract function digest_log();
48
49 /**
50 */
51 private final function move_log()
52 {
53 if (file_exists($this->clean_log_file)) {
54 rename($this->clean_log_file, $this->final_log);
55 echo "Publish.";
56 }
57 echo "\n";
58 }
59
60 /**
61 */
62 private final function cleanup()
63 {
64 file_exists($this->log_file) ? unlink($this->log_file) : null;
65 }
66 }

  ViewVC Help
Powered by ViewVC 1.1.28