amazon-web-services - 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...
解决方案
编写以下脚本~/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
推荐阅读
- c# - 在 mvc 应用程序中找不到资源 api
- c# - 大数的模计算(C#)
- regex - 匹配基于正则表达式模式匹配的字符串
- python - 将浮点格式化为固定宽度的python
- xml - SSIS——读取行集中的标签并存储在表中
- php - 在 Laravel 中扩展另一个页面
- excel - 自动填充公式到数据 VBA 的末尾
- ios - UINavigationItem 外观不一致
- visual-studio-2015 - SSIS 2008 包未在 Visual Studio 2015 中打开
- c++ - OpenSSL:EC_POINT_set_compressed_coordinates_GFp 段错误