答案1
根据链接的问题,您似乎想要记录从中获得的统计数据rsync --stats
,即以下内容:
Number of files: 4
Number of files transferred: 0
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 66
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 80
Total bytes received: 13
sent 80 bytes received 13 bytes 186.00 bytes/sec
total size is 0 speedup is 0.00
您可以使用 AWK 解析该输出中有趣的部分,然后输出适当的 SQL 语句。如下所示:
#!/usr/bin/awk -f
/^Number of files: / {
num_files = $4;
}
/^Number of files transferred: / {
num_tranferred = $5;
}
/* etc... */
END {
printf("INSERT INTO some_table (num_files, num_transferred) \
VALUES (%d, %d);\n", num_files, num_transferred);
}
答案2
你可能正在尝试用锤子敲螺丝 :) 你绝对应该使用 Perl、Python 或 Ruby 之类的语言。它会更快,更稳定。实际上,甚至 PHP 也会更好 :)