簡體   English   中英

用於壓縮文件並發送帶有郵件的zip的腳本

[英]Script for compress of file and send zip with mail

我有一個日志文件夾(as.log),並用腳本(基本for循環)填充此日志。 如果此文件夾的大小大於150kb,則應壓縮此文件夾,並且其名稱應包含日期。 最后,zip文件應與郵件一起自動發送。

FILESIZE=$(stat -c%s as.log) 
if [" $FILESIZE" -gt "150000" ]; then 
zip -r "as.log-$(date +"%Y-%m-%d").zip" as.log 
here sendmail kaanmrzl@gmail.com < as.log.zip
here truncate -s 0 as.log
fi

我的自動填充腳本是

for i in {1..1000}
  do 
   echo "$i log kaydı" >> as.log 
done 

我從未在bash上發送過電子郵件,但是這對於壓縮超過150K的文件夾應該有效。 希望能幫助到你。

#!/bin/bash

directory="/path/to/log_dir"
threshold=150
output="/path/to/log-$(date +"%Y-%m-%d").zip"

dir_size=$(du -k $directory | cut -f1)
if [ "$dir_size" -gt "$threshold" ]
then
    zip -r $output $directory
fi

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM