在 Linux 上应如何解释最后输出中的时间戳?

发布于 2024-07-13 23:41:05 字数 238 浏览 6 评论 0原文

$ 最后 -aid 
  foouser pts/12 2月15日星期日 07:30 - 15:23 (2+07:52) XXX.YYY.ZZZ.QQQ 
  

Sun Feb 15 07:30 - 15:23 部分非常明显。 该用户于周日 7:30 登录。 但(2+07:52)还不清楚。 7:52 是两个时间之差,那么 2+ 部分是多少呢?

$ last -aid
foouser  pts/12       Sun Feb 15 07:30 - 15:23 (2+07:52)     XXX.YYY.ZZZ.QQQ

The Sun Feb 15 07:30 - 15:23 part is pretty obvious. The user logged in at 7:30 on Sunday. But (2+07:52) is unclear. 7:52 is the difference between the two times, but what's the 2+ part?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温柔女人霸气范 2024-07-20 23:41:05

使用源代码,Luke:

sprintf(length, "(%d+%02d:%02d)", days, hours, mins);

这是来自 Debian 上的 sysvinit 源代码包。

给那些不懂 C 语言的人的提示:这是天数。

Use the source, Luke:

sprintf(length, "(%d+%02d:%02d)", days, hours, mins);

This is from the sysvinit source package on Debian.

Hint for those without knowledge in C: it's the number of days.

静若繁花 2024-07-20 23:41:05

括号之间的字符串是会话的持续时间。 正如您所注意到的,时间是结束时间和开始时间之间的差。 2+ 是天数 跳注意到

在某些时候,这个问题可能应该转移到服务器故障,因为它最有可能引起系统管理员的兴趣。

一旦您知道自己在看什么,它就是一种相当可读的格式。 如果我设计输出,我想我会将星期几设为可选,并将整个结束日期放入字符串中。 更好的是让日期戳是可配置的。 这样,输出就可以更容易地被另一个程序使用。

如果用户已注销会话,则可以使用正则表达式轻松选出实际持续时间:

$ last | perl -lne 'print "$2 days, $3 hours, $4 minutes" if /\(((\d+)\+)(\d{2}):(\d{2})\)$/'
17 days, 05 hours, 23 minutes
3 days, 23 hours, 16 minutes
14 days, 06 hours, 09 minutes
23 days, 04 hours, 54 minutes
16 days, 06 hours, 57 minutes
...

The string between the parentheses is the duration of the session. As you note, the time is the difference between the end and start times. The 2+ is the number of days as hop noted.

At some point, this question probably should be moved over to Server Fault since it's most likely to be of interest to System Administrators.

It's a fairly readable format once you know what you are looking at. If I were designing the output, I think I'd make the day of the week optional and put the entire end date in the string instead. Even better would be to let the date stamp be configurable. That way, the output could be more easily used by another program.

The actual duration, if the user has logged out of the session is fairly easy to pick out with a regular expression:

$ last | perl -lne 'print "$2 days, $3 hours, $4 minutes" if /\(((\d+)\+)(\d{2}):(\d{2})\)$/'
17 days, 05 hours, 23 minutes
3 days, 23 hours, 16 minutes
14 days, 06 hours, 09 minutes
23 days, 04 hours, 54 minutes
16 days, 06 hours, 57 minutes
...
恍梦境° 2024-07-20 23:41:05

那可能是几天,但我不确定; 这也不是一个编程问题。

Those might be days but I'm not sure; also this is not a programming question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文