1 |
rda |
1525 |
<?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 |
|
|
} |