网站用花生壳nas做存储,西安工程信息交易中心,如何删除错误wordpress,网站引流怎么做前言 如题#xff0c;原本打算在代码中自己写一个类去管理将打印信息收集到log日志中#xff0c;忽然想到#xff0c;其实也可以写sh脚本 简单demo1
#!/bin/bash# 启动应用程序 test#xff0c;并将标准输出和标准错误输出都追加到 log 文件中
./test output.log…前言 如题原本打算在代码中自己写一个类去管理将打印信息收集到log日志中忽然想到其实也可以写sh脚本 简单demo1
#!/bin/bash# 启动应用程序 test并将标准输出和标准错误输出都追加到 log 文件中
./test output.log 21
在这个脚本中假设应用程序 test 是当前目录下的一个可执行文件。脚本会将 test 的标准输出stdout和标准错误输出stderr都追加到 output.log 文件中。
效果 简单demo2增加日期时间
#!/bin/bash# 创建一个带有时间戳的函数
timestamp() {date %Y-%m-%d %T
}# 启动应用程序 test并将标准输出和标准错误输出都追加到 log 文件中
./test | while IFS read -r line; doecho $(timestamp) $line output.log
done
效果 简单美化
#!/bin/bash# 创建一个带有时间戳的函数
timestamp() {date %Y-%m-%d %T
}# 启动应用程序 test并将标准输出和标准错误输出都追加到 log 文件中
./test | while IFS read -r line; doecho -e \n$(timestamp) | $line output.log
done
效果 实时查看命令
tail -f output.log
当文件更新的时候tail也会实时更新打印更多命令自行百度。
实时查看最新的20条数据
tail -n 20 -f output.log