-2

I need to collect vmstat command for a day. But some time I start the command at day time, I want it to finish at 23:59. what is the best way to calculate remaining seconds in day using shell scipt or perl script?

Thanks SR

4

2 回答 2

4

你可以在 Perl 中使用DateTime来做到这一点。使用 time 创建今天的对象00:00:00,添加一天,将其转换为纪元秒并减去程序的起始时间戳。

use strict;
use warnings;
use DateTime;
print DateTime->today( time_zone => 'local' )->add(days => 1)->epoch - time;
于 2013-04-27T17:29:51.517 回答
2

在 bash 中:

$ echo $(( $(date --date="00:00 next day" +%s) - $(date +%s) ))
于 2013-04-27T18:42:07.353 回答