如何将 shell 会话的所有控制台输出发送到日志文件
我不确定这是否可能,但在登录后自动将所有控制台输出(stderr 和 stdout)自动发送到日志文件会非常方便。我希望它在每次登录和发送时创建一个唯一的文件所有这些输出到我的日志目录。预先感谢您提供任何帮助我进行设置的想法。
I am not sure if this is possible but it would be terribly handy to automatically tee all console output (stderr and stdout) to a log file starting after logging in. I would want it to create a unique file each time I log in and tee all that output to my logs directory. Thanks in advance for any ideas to help me set this up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,唯一接近您想要的实用程序是
script
命令这会生成您的会话的完整记录。要为所有登录自动执行此操作,您可能需要创建一个包装脚本并将其设置为默认 shell。
网络上的一场快速小冲突导致了这个脚本:http://snipt.net /d1s4st3r/script-that-acts-as-a-login-shell-replacement-to-log-everything-an-user-does/
我没有使用过它,但是在乍一看,它看起来就像罐头上说的那样。
The only utility I know of that comes close to what you want is the
script
command which makes a full transcript of your session.To do this automatically for all your logins, you'll probably need to create a wrapper script and set that as your default shell.
A quick skirmish on the web resulted in this script: http://snipt.net/d1s4st3r/script-that-acts-as-a-login-shell-replacement-to-log-everything-an-user-does/
I haven't used it, but at a glance it looks like it does as it says on the can.
这是描述命令“脚本”的站点的链接,该命令采用日志文件的参数来创建。将其放在 .login 文件中将导致每次登录时都会创建日志。使用日期和时间生成日志文件名将为每个会话创建单独的日志。输入 Ctrl-D 将结束脚本会话我还没有对此进行测试,但我很确定这就是所述问题的解决方案。
http://lxtipsandtricks.blogspot.com/2009 /03/how-to-capture-unix-console-screen.html
Here is a link to a site describing the command "script" which takes a paramater of the log file to create. Placing this in the .login file will cause the log to be created everytime you login. Using the Date and Time to generate the log file name will create seperate logs per session. Entering Ctrl-D will end the script session I have not tested this yet but I am pretty sure this is the solution to the problem as stated.
http://lxtipsandtricks.blogspot.com/2009/03/how-to-capture-unix-console-screen.html