首页 > 解决方案 > Log Each Request And Output In EC2 Ubuntu or Linux

问题描述

I have an AWS EC2 instance and in this instance, I have some cron jobs. This cron jobs looks like:

0 5 * * mon curl -Ssi -X POST http://example.com 

And I have some manual outputs like:

echo "output: hello..."

I want to store these actions on a log file in EC2 ubuntu or linux instance. Is it possible? Any suggestion?

Expected output:

[2021-10-10 ...] - POST http://example.com
[2021-10-11 ...] - output: hello...

标签: amazon-web-servicesubuntuamazon-ec2

解决方案


编写以下脚本~/bin/site-detector

#!/bin/bash
source ~/.bash_profile

log_file=/tmp/site-detector.log
curl -Ssi -X POST http://example.com  >> $log_file
echo "Detected @ $(date)" >> $log_file
echo " " >> $log_file

使您的脚本可执行:

chmod a+x ~/bin/site-detector

更新您的 crontab 脚本:

0 5 * * mon ~/bin/site-detector 

推荐阅读