-
Notifications
You must be signed in to change notification settings - Fork 0
/
sawmill_export_podcasts
31 lines (23 loc) · 1.22 KB
/
sawmill_export_podcasts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Export Sawmill stats to CSV by name
# Usage: /usr/local/bin/sawmill_export_podcasts name
#!/usr/bin/perl -w
use strict;
my $sawmill = "/usr/local/bin/sawmill/sawmill7.2.18";
my $outputPath = "/var/www/";
# localtime minus 30 days
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time - (86400 * 30));
$year += 1900;
my @month_abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my $exportStation = $ARGV[0] || "skyradio";
my $exportMonth = $ARGV[1] || $month_abbr[${mon}];
my $exportYear = $ARGV[2] || $year;
my $exportFilename = "podcasts_${exportStation}_${exportMonth}.csv";
print "${exportStation}\n";
print "${exportMonth}\n";
print "${exportYear}\n";
print "${exportFilename}\n";
# kill Sawmill to prefend 'Cannot generate report...' error
system("killall sawmill7.2.18");
system("${sawmill} -p srg_webserver_varnish_logs -a ect -rn page -f \"(date_time >= '01/${exportMonth}/${exportYear} 00:00:00') and (date_time <= '31/${exportMonth}/${exportYear} 23:59:59') and (page matches '*/cdn/podcast_${exportStation}*')\" statistics.reports.page.report_elements.page.only_bottom_level_items true > ${outputPath}${exportFilename}");
# start Sawmill again
system("/usr/local/bin/sawmill/sawmill7.2.18 &");