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
你可以在 Perl 中使用DateTime来做到这一点。使用 time 创建今天的对象00:00:00
,添加一天,将其转换为纪元秒并减去程序的起始时间戳。
use strict;
use warnings;
use DateTime;
print DateTime->today( time_zone => 'local' )->add(days => 1)->epoch - time;
在 bash 中:
$ echo $(( $(date --date="00:00 next day" +%s) - $(date +%s) ))