goktugtirak/automation-scripts

GitHub: goktugtirak/automation-scripts

一套基于 Bash 和 cron 的 Linux 运维自动化脚本集,解决系统监控、日志分析和文件备份等日常管理任务的定时执行需求。

Stars: 0 | Forks: 0

# 自动化脚本 本项目是一个模块化 shell 脚本的集合,旨在自动化常见的 DevOps 和系统管理任务。这些脚本设计为通过 cron 作业自动运行,并生成结构化的日志输出,以便用于监控和审计。 ## 功能 - **用户会话监控** (`cron_session_report.sh`): - 按用户和服务(如 cron)统计登录和注销次数。 - 生成每日会话活动报告。 - **失败认证检测** (`failed_auth_report.sh`): - 解析 `/var/log/auth.log` 以统计失败的登录尝试。 - 检测暴力破解尝试,并记录失败次数过多的 IP。 - **磁盘使用情况报告** (`disk_usage_report.sh`): - 监控所有已挂载文件系统的磁盘使用情况。 - 当使用量超过设定的阈值时发出警告。 - 附带时间戳报告可用和已用空间。 - **文件备份** (`backup.sh`): - 将 `data_files/` 的内容打包,并以带时间戳的名称存储在 `backup_files/` 中。 - 确保定期备份重要的文件和目录。 ## 项目结构 ``` automation-scripts/ ├── backup.sh ├── cron_session_report.sh ├── disk_usage_report.sh ├── failed_auth_report.sh ├── backup_files/ # Source files to be backed up ├── data_files/ # Backup archives saved here ├── example_logs/ # Sample input logs for testing └── script_logs/ # All generated log files are stored here ``` ## Cron 作业配置(Crontab) 要自动化这些脚本,请将以下行添加到相应用户的 crontab(`crontab -e`)中: ``` # 每天 06:00 AM 运行 session 监控 0 6 * * * /path/to/automation-scripts/cron_session_report.sh # 每天 06:10 AM 运行失败 authentication 报告 10 6 * * * /path/to/automation-scripts/failed_auth_report.sh # 每天 06:20 AM 运行磁盘使用情况报告 20 6 * * * /path/to/automation-scripts/disk_usage_report.sh # 每天 02:00 AM 执行文件备份 0 2 * * * /path/to/automation-scripts/backup.sh ``` ## 日志 所有脚本都会将其输出写入位于 `script_logs/` 目录下的日志文件中。这些日志带有时间戳且仅允许追加,确保了系统事件的持久化和可追溯性。 ## 使用的技术 - **Bash 脚本**(兼容 POSIX) - **Cron**(用于自动化) - **Linux 系统工具**:`df`、`grep`、`awk`、`date`、`tar` 等。
标签:Bash, 定时任务, 应用安全, 数字取证, 系统运维, 自动化脚本