程序/脚本记录小时的建议

时间:2017-01-23 17:59:58

标签: c++ linux windows logging signals

这是一个稍微开放的问题,但我正在寻找有关如何解决这个问题的一般指导,因为我真的不知道从哪里开始:

对于我现在的雇主,我需要每周记录我的工作时间。因此,我有兴趣编写一个程序(我最熟悉C ++)或者每次登录我的机器并让它进入睡眠时“无形地”捕获的脚本。社区可以推荐如何做到这一点的方法吗?

我将更多地描述我的工作环境:

我登录到一个Windows框,我主要用于电子邮件和网页浏览,但我的大多数开发都是通过VNC进入Linux机器盒完成的。所以我登录Windows后几乎立即登录Linux框。 Linux盒子是我自己的,所以我可以自由编写二进制/脚本守护进程来运行它。

我的第一个想法是写一个程序,以某种方式“困住”windows登录和睡眠事件,类似于你如何捕获SIGINT等等 - 但我不知道这是否或如何可能。

我对Linux环境很新,很天真,所以我不知道为什么会这样:但是当我恢复VNC会话时,我通常不会提示输入密码(我通常会看到有关崩溃的错误与x-screensaver一起发生)。我很少提示输入我的密码,但是我还不知道当我被问及什么时候我不知道时有什么区别。我提到这个的原因是因为如果存在“捕获登录”这样的事情,那么在Linux机器上执行此操作似乎是不可行的,因为这种不一致的密码提示。

再一次:我的目标是有一些东西可以捕获我的登录/注销/睡眠活动,而不是每次登录/退出或让我的系统进入睡眠状态时都会启动命令/脚本。如果对执行此操作的守护程序进行编码/编写脚本是不合理的,是否有可以执行此操作的现成(和免费)解决方案?如果没有 - 也就是说,如果唯一的解决方案是每次登录/退出或让我的系统进入睡眠状态时手动运行某些东西 - 那么我可以将程序拼凑起来这样做。

感谢您的指导和建议。

3 个答案:

答案 0 :(得分:2)

您可以查看“last”命令。在another stack overflow question中,这被列为列出登录/注销时间。在我的机器上,这个命令也给了我看起来像持续时间的值(:我认为)。

如果您想自己研究协议登录的可能性,在“.bashrc”中添加命令可以让您在打开shell时运行自定义命令。但是,此方法会为您打开的每个控制台运行命令,而不仅仅是在您登录时。

我想查看“最后”命令可以轻松地为您提供所需的结果。

答案 1 :(得分:0)

嗯,如果情况紧急,你可以随时采取以下简单的解决方案,然后转移到更复杂的解决方案......在你所处的任何工作环境中编写脚本,从开始到行动的时间。您可以在输入任何输入之前将其停止,并获取您提供此输入所需的时间。

将这些结果输出到一些文本文件中并将它们加载到一些代码中以将结果解析为可呈现的格式,在DBMS中会很有趣。将脚本设置为调度程序以自动启动...

我在这里看到的一个问题是工作环境。你说Windows机器是你自己的,但你想记录工作时间吗?如果是这样,当您阅读与工作相关的电子邮件时,自动启动脚本会变得有点复杂......在Linux环境中设置脚本并且可能添加近似花费在Windows机器做的工作相关的东西,但你没有提供不属于你的Linux机器的限制。也许你也可以编写一个脚本来加载机器并将加载包装在一个功能测量时间内,直到你关闭机器......当然,如果你经常退出机器,这会变得很烦人。

确定有更合适的方法可以完全自动化这个过程,但是......取决于你想要什么以及你受限制的东西,所以把它作为一个指针。

答案 2 :(得分:0)

我找到了一个有趣的解决方案:Windows PowerShell中的Get-WinEvent命令。 E.g:

PS C:\Windows\system32> Get-WinEvent -FilterHashtable @{starttime='1/20/2017';endtime='1/21/2017';logname='security';id=4648,4634}

TimeCreated                             ProviderName                                                                 Id Message
-----------                             ------------                                                                 -- -------
1/20/2017 6:20:38 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 5:42:20 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 5:42:20 PM                    Microsoft-Windows-Security-Auditing                                        4648 A logon was attempted using explicit...
1/20/2017 5:42:20 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 5:42:20 PM                    Microsoft-Windows-Security-Auditing                                        4648 A logon was attempted using explicit...
1/20/2017 5:42:20 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 5:42:20 PM                    Microsoft-Windows-Security-Auditing                                        4648 A logon was attempted using explicit...
1/20/2017 5:42:19 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 5:42:18 PM                    Microsoft-Windows-Security-Auditing                                        4648 A logon was attempted using explicit...
1/20/2017 5:30:32 PM                    Microsoft-Windows-Security-Auditing                                        4648 A logon was attempted using explicit...
1/20/2017 5:30:29 PM                    Microsoft-Windows-Security-Auditing                                        4648 A logon was attempted using explicit...
1/20/2017 4:34:36 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 2:49:34 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 2:07:06 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 1:48:06 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 1:48:06 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 1:45:09 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 1:45:09 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 1:42:55 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 1:42:54 PM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 12:56:32 PM                   Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 12:16:58 PM                   Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 12:16:58 PM                   Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 12:16:58 PM                   Microsoft-Windows-Security-Auditing                                        4648 A logon was attempted using explicit...
1/20/2017 12:16:58 PM                   Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 12:16:58 PM                   Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 12:16:58 PM                   Microsoft-Windows-Security-Auditing                                        4648 A logon was attempted using explicit...
1/20/2017 11:23:29 AM                   Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 10:06:22 AM                   Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 9:48:06 AM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 9:48:06 AM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 9:45:19 AM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 9:45:09 AM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 9:43:47 AM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 9:43:47 AM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 9:43:47 AM                    Microsoft-Windows-Security-Auditing                                        4648 A logon was attempted using explicit...
1/20/2017 9:43:47 AM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 9:43:47 AM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 9:43:47 AM                    Microsoft-Windows-Security-Auditing                                        4648 A logon was attempted using explicit...
1/20/2017 9:43:25 AM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 9:42:57 AM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 9:42:56 AM                    Microsoft-Windows-Security-Auditing                                        4634 An account was logged off....
1/20/2017 9:42:52 AM                    Microsoft-Windows-Security-Auditing                                        4648 A logon was attempted using explicit...

其中4648表示登录事件,4634表示注销事件。

从这里开始,我想我剩下的目标是将其包装在某种脚本中,该脚本计算第一次登录和最后一次注销之间的时间。

我想这可能会转到SuperUser,但我原本不知道问题/答案会在哪里发生。