如何在输出文件中标记日志

如何在输出文件中标记日志

我有:

我在 crontab 中有一些命令,例如:

55 11 * * * curl -d '{"explorerId":'$(cat /root/id)', "turnOff":true}' -H "Content-Type: application/json" -X POST http://localhost:8080/descriptions >> log/curl.log 2>&1

此命令执行某些操作并将结果保存在文件 curl.log 中

那需要:

我希望每个注释都添加一个包含信息的字符串,例如:

Date: 15.09.2018. 
Execute command: description
Result:

#...result of log from curl command

答案1

你可以尝试这个:

55 11 * * * { echo -e "date: $(date -I)\nExecute command: description\nResult:\n"; curl -d '{"explorerId":'$(cat /root/id)', "turnOff":true}' -H "Content-Type: application/json" -X POST http://localhost:8080/descriptions ;} >> log/curl.log 2>&1

它将回显日期、描述和结果并将其附加到日志中。

相关内容