邮件帐户和松散文件夹使用 AWK 向 CSV 报告。如何从这个例子中实现这一点?
Mail accounts and loose folders report to CSV using AWK. How to achieve that from this example?
我正在使用 this shellscript 为每个用户生成收件箱列表和所有文件夹的大小,如下所示:
john.doe@mydomain.com's max mailbox size = 0 MB, current mailbox size = 18,78 GB.
size (MB) msgcount unread folder
--------- --------- ---------- ----------------------------
0 0 0 /Chats
42 0 /Drafts
13118 28014 37 /Inbox
0 6 0 /Junk
0 1 0 /Orders
323 13385 17 /Raster
5772 3760 0 /Sent
1 183 0 /Payments
0 2 0 /Trash
-------------------------------------------------------
我需要从中挖掘数据并将其放入 CSV 文件中,其中每一行都有电子邮件帐户以及垃圾箱、已发送和垃圾文件夹值的值。问题是 "Inbox",因为正如您所见,用户在树外创建了文件夹(如 "Raster" 和 "Payments")。因此,我需要找到一种方法来汇总此报告中每个用户的 "thrash/sent/junk" 以外的所有内容。
下面的awk
可以作为起点。它收集数据,并将数据读入内存,并在 END 事件中打印摘要。
awk -v OFS=, '
function do_print () {
print user, s_trash, n_trash, s_sent, n_sent, s_junk, n_junk, s_other, n_other
}
/max mailbox/ { user = ;
s_trash = n_trash = s_sent = n_sent = s_junk = n_junk = s_other = n_other = 0
next ;
}
# Parse lines starting with '/'
~ /^\/Trash/ { s_trash += ; n_trash += ; next }
~ /^\/Sent/ { s_sent += ; n_sent += ; next }
~ /^\/Junk/ { s_junk+= ; n_junk += ; next }
# Everything else goes to other
~ /^\// { s_other += ; n_other = ; next }
# Print whenever there is a line of '='
/==================/ { do_print() }
END { do_print() }
'
这是我的php脚本,用于从域
中的所有用户获取配额
它输出这样的东西
function zmbGetQuotaUsageRequest($domain, $adminAuthToken, $output='array') {
# URL que somente administradores conseguem acessar
$url = 'https://mail.meudominio.com.br/service/wsdl/ZimbraAdminService.wsdl';
$requestParams = array(
'allServers' => 1,
'domain' => $domain,
);
$context = stream_context_create([
'ssl' => [
'allow_self_signed' => true,
'SNI_enabled' => true,
'verify_peer' => false,
'verify_peer_name' => false,
]
]);
try {
$soapHeader = array(
new SoapHeader(
'urn:zimbra',
'context',
new SoapVar('<ns2:context><authToken>'.$adminAuthToken.'</authToken></ns2:context>', XSD_ANYXML)
)
);
$client = new SoapClient($url, [
'stream_context' => $context,
]);
$client->__setSoapHeaders($soapHeader);
$response = $client->GetQuotaUsageRequest($requestParams);
}
catch (SoapFault $e) {
$fault = $client->__soap_fault;
$code = (string) $fault->detail->Error->Code;
$reason = (string) $fault->faultstring;
$response['fault'] = [ 'code' => $code, 'reason' => $reason ];
return $response;
}
# Converter stdClass Object em array
$response = json_decode(json_encode($response), true);
# Converter a resposta wsdl do zimbra em array usando email como chave
$banco = [];
foreach ($response['account'] as $idx => $atr) {
$name = $atr['name'];
unset($atr['name'], $atr['id']);
$banco[$name] = $atr;
}
ksort($banco);
$bancojson = json_encode($banco, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
return ($output == 'json') ? $bancojson : $banco;
}
我正在使用 this shellscript 为每个用户生成收件箱列表和所有文件夹的大小,如下所示:
john.doe@mydomain.com's max mailbox size = 0 MB, current mailbox size = 18,78 GB.
size (MB) msgcount unread folder
--------- --------- ---------- ----------------------------
0 0 0 /Chats
42 0 /Drafts
13118 28014 37 /Inbox
0 6 0 /Junk
0 1 0 /Orders
323 13385 17 /Raster
5772 3760 0 /Sent
1 183 0 /Payments
0 2 0 /Trash
-------------------------------------------------------
我需要从中挖掘数据并将其放入 CSV 文件中,其中每一行都有电子邮件帐户以及垃圾箱、已发送和垃圾文件夹值的值。问题是 "Inbox",因为正如您所见,用户在树外创建了文件夹(如 "Raster" 和 "Payments")。因此,我需要找到一种方法来汇总此报告中每个用户的 "thrash/sent/junk" 以外的所有内容。
下面的awk
可以作为起点。它收集数据,并将数据读入内存,并在 END 事件中打印摘要。
awk -v OFS=, '
function do_print () {
print user, s_trash, n_trash, s_sent, n_sent, s_junk, n_junk, s_other, n_other
}
/max mailbox/ { user = ;
s_trash = n_trash = s_sent = n_sent = s_junk = n_junk = s_other = n_other = 0
next ;
}
# Parse lines starting with '/'
~ /^\/Trash/ { s_trash += ; n_trash += ; next }
~ /^\/Sent/ { s_sent += ; n_sent += ; next }
~ /^\/Junk/ { s_junk+= ; n_junk += ; next }
# Everything else goes to other
~ /^\// { s_other += ; n_other = ; next }
# Print whenever there is a line of '='
/==================/ { do_print() }
END { do_print() }
'
这是我的php脚本,用于从域
中的所有用户获取配额它输出这样的东西
function zmbGetQuotaUsageRequest($domain, $adminAuthToken, $output='array') {
# URL que somente administradores conseguem acessar
$url = 'https://mail.meudominio.com.br/service/wsdl/ZimbraAdminService.wsdl';
$requestParams = array(
'allServers' => 1,
'domain' => $domain,
);
$context = stream_context_create([
'ssl' => [
'allow_self_signed' => true,
'SNI_enabled' => true,
'verify_peer' => false,
'verify_peer_name' => false,
]
]);
try {
$soapHeader = array(
new SoapHeader(
'urn:zimbra',
'context',
new SoapVar('<ns2:context><authToken>'.$adminAuthToken.'</authToken></ns2:context>', XSD_ANYXML)
)
);
$client = new SoapClient($url, [
'stream_context' => $context,
]);
$client->__setSoapHeaders($soapHeader);
$response = $client->GetQuotaUsageRequest($requestParams);
}
catch (SoapFault $e) {
$fault = $client->__soap_fault;
$code = (string) $fault->detail->Error->Code;
$reason = (string) $fault->faultstring;
$response['fault'] = [ 'code' => $code, 'reason' => $reason ];
return $response;
}
# Converter stdClass Object em array
$response = json_decode(json_encode($response), true);
# Converter a resposta wsdl do zimbra em array usando email como chave
$banco = [];
foreach ($response['account'] as $idx => $atr) {
$name = $atr['name'];
unset($atr['name'], $atr['id']);
$banco[$name] = $atr;
}
ksort($banco);
$bancojson = json_encode($banco, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
return ($output == 'json') ? $bancojson : $banco;
}