获取启动时间

获取启动时间

我有一个树莓派。我有一个 crontab 正在运行并告诉它在每天中午重新启动(sudo reboot now)。

这是结果last reboot -F

myuser@mypiname:~ $ last -F reboot
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970   still running
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970   still running
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970   still running
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Tue Oct 27 12:00:33 2020 (18562+11:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Tue Oct 27 12:00:03 2020 (18562+11:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Mon Oct 26 12:01:00 2020 (18561+11:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Mon Oct 26 12:00:31 2020 (18561+11:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Mon Oct 26 12:00:03 2020 (18561+11:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Mon Oct 26 12:00:03 2020 (18561+11:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Mon Oct 26 12:00:03 2020 (18561+11:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Sun Oct 25 12:00:33 2020 (18560+11:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Sun Oct 25 12:00:03 2020 (18560+11:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Sat Oct 24 12:00:33 2020 (18559+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Sat Oct 24 12:00:04 2020 (18559+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Fri Oct 23 12:00:03 2020 (18558+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Thu Oct 22 12:00:44 2020 (18557+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Thu Oct 22 12:00:11 2020 (18557+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Wed Oct 21 12:00:06 2020 (18556+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Tue Oct 20 12:00:33 2020 (18555+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Tue Oct 20 12:00:04 2020 (18555+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Mon Oct 19 12:00:33 2020 (18554+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Mon Oct 19 12:00:03 2020 (18554+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Sun Oct 18 12:00:04 2020 (18553+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Sat Oct 17 12:00:04 2020 (18552+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Fri Oct 16 12:00:33 2020 (18551+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Fri Oct 16 12:00:03 2020 (18551+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Fri Oct 16 12:00:03 2020 (18551+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Thu Oct 15 12:00:34 2020 (18550+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Thu Oct 15 12:00:04 2020 (18550+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Wed Oct 14 12:00:04 2020 (18549+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Wed Oct 14 12:00:04 2020 (18549+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Wed Oct 14 12:00:04 2020 (18549+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Tue Oct 13 12:00:33 2020 (18548+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Tue Oct 13 12:00:03 2020 (18548+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Mon Oct 12 12:00:36 2020 (18547+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Mon Oct 12 12:00:04 2020 (18547+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Sun Oct 11 12:00:34 2020 (18546+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Sun Oct 11 12:00:04 2020 (18546+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Sat Oct 10 12:00:33 2020 (18545+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Sat Oct 10 12:00:04 2020 (18545+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Fri Oct  9 12:02:03 2020 (18544+10:02)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Fri Oct  9 12:00:04 2020 (18544+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Thu Oct  8 12:00:34 2020 (18543+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Thu Oct  8 12:00:04 2020 (18543+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Wed Oct  7 12:00:33 2020 (18542+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Wed Oct  7 12:00:04 2020 (18542+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Tue Oct  6 12:00:04 2020 (18541+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Mon Oct  5 17:38:18 2020 (18540+15:38)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Mon Oct  5 12:00:04 2020 (18540+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Sun Oct  4 12:00:33 2020 (18539+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Sun Oct  4 12:00:03 2020 (18539+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Sat Oct  3 12:00:04 2020 (18538+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Fri Oct  2 12:00:03 2020 (18537+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Fri Oct  2 12:00:03 2020 (18537+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Thu Oct  1 18:07:11 2020 (18536+16:07)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Thu Oct  1 18:07:11 2020 (18536+16:07)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Thu Oct  1 18:07:11 2020 (18536+16:07)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Thu Oct  1 18:07:11 2020 (18536+16:07)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Thu Oct  1 18:07:11 2020 (18536+16:07)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Thu Oct  1 12:01:00 2020 (18536+10:00)
reboot   system boot  4.19.66-v7+      Thu Jan  1 01:00:01 1970 - Thu Oct  1 12:00:31 2020 (18536+10:00)

wtmp begins Thu Oct  1 10:28:43 2020

我今天下午 2 点左右拔掉了 Raspberry Pi 的插头(27/10/2020 13:55:XX),但这里没有显示它已被拔掉(可能是因为它不是重新启动)。

如何获取上次启动时间而不是上次重新启动时间?另外,我希望拥有“所有”启动时间,而不仅仅是最后一次。

我尝试过last boot -F,但它没有显示任何内容。

答案1

获取启动时间

您在 Pi 上遇到的第一个问题。是在设备从网络时间服务器获取时间之前创建启动日志。该设备没有电池支持的时钟,因此从 开始1970-01-01T00:00(这也打破了who -b)。

你和我的日志中的第二个日期看起来很合理,但实际上是关闭时间。

您需要找到一种方法来记录该设备的启动时间。

一些想法

uptime --since给出正确的启动时间。 (系统现在有正确的时间)。

启动或重新启动

接下来我们需要问,重启与启动是什么意思?只有引导。但是我们可以查看是否有关闭过程。我们可以看看时差。我们可以(我不知道这是否被记录)查看什么类型的关闭,是重新启动类型的关闭吗?

答案2

尝试

 $ who -b

您将获得上次启动的时间。

答案3

我寻求另一种解决方案。我不需要启动时的确切秒数,因此我选择cron在重新启动时使用日志记录:

@reboot  echo "Rebooting at $(date)" >> /path/to/some/file

它的灵感来自@ctrl-alt-delor 的评论。

相关内容