linux - 将运行时日志存储在文件夹中

标签 linux shell command

我正在 Linux 环境中运行 shell 脚本来创建一些日志(动态日志文件)作为文本文件。

我想在某个特定时间后将创建的所有日志文件存储到一个文件夹中。

那么我该怎么做呢?谁能建议一些命令?

提前致谢。

最佳答案

在脚本中,您可以将该目录定义为变量,并且可以在整个脚本中使用该目录。

#!/bin/bash

LOG_DIR=/tmp/logs
LOG_FILE=$LOG_DIR/log_file.$$ ## $$ will create the different log file for each and every run
                              ## You can also do it by using some time stamp using date command.

<Your commands>  >> $LOG_FILE

关于linux - 将运行时日志存储在文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26730148/

相关文章:

linux - 编写 shell 脚本来编译和调度我的服务器程序?

bash - 这些流重定向如何工作?

c++ - 在 Qt 中以 root 身份执行 Linux 命令

linux - RTI connext DDS 的 UDP 传输中使用了多个端口?

regex - ansible lineinfile 模块用多行替换单行

c++ - 强制或阻止使用特定次要版本的 libstdc++

linux - 如何复制文件名与文本文件中的列表字符串部分匹配的文件?

Java getInputStream SocketTimeoutException 而不是 NoRouteToHostException

bash - 对 grep 列出的*每个*项目执行操作

linux - 命令 'c ..' 的作用是什么?