From 3a8d749ad6ff6e73ca8cac3cf3b337b670001a0c Mon Sep 17 00:00:00 2001 From: TheK4n Date: Sat, 2 Oct 2021 01:05:04 +0300 Subject: [PATCH] add cron tips add del_logs.sh --- README.md | 10 ++++++++++ functions/del_logs.sh | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 functions/del_logs.sh diff --git a/README.md b/README.md index 48cad89..cbcedf3 100644 --- a/README.md +++ b/README.md @@ -106,4 +106,14 @@ sudo systemctl status .service sudo systemctl enable .service ``` +### Cron + +```crontab -e``` + +```0 0 1 1 * command.sh``` - Every year in 1 January 00:00:00 \ +```*/1 * * * * command.sh``` - Every minute\ +```0 */3 * * 2,5 command.sh``` - One time per 3 hours in Tue and Fri\ +```0 0,12 1 */2 * command.sh``` - At minute 0 past hour 0 and 12 on day-of-month 1 in every 2nd month + +

diff --git a/functions/del_logs.sh b/functions/del_logs.sh new file mode 100644 index 0000000..65ffb36 --- /dev/null +++ b/functions/del_logs.sh @@ -0,0 +1,17 @@ +#!/usr/bin/bash + +# removes log files with size greater then 100Mb + +for i in $(sudo du -a /var/log/* | sort -hr | tr '\t' ':') +do + + size_file=( $(echo "$i" | tr ':' ' ') ) + + size="${size_file[0]}" + file="${size_file[1]}" + + if [ "$size" -ge 102400 ] && [ -f "$file" ]; then + sudo rm "$file" + fi + +done