简体   繁体   English

用于压缩文件并发送带有邮件的zip的脚本

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

I have a log folder(as.log) and I fill this log with script(basic for loop). 我有一个日志文件夹(as.log),并用脚本(基本for循环)填充此日志。 If this folder size is bigger than 150kb, this folder should be compressed and its name should contain date. 如果此文件夹的大小大于150kb,则应压缩此文件夹,并且其名称应包含日期。 Finally zip file should be sent with mail automatically. 最后,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

my auto filler script is 我的自动填充脚本是

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

I've never sent an email on bash, but this should work for zipping a folder which exceeds size of 150K. 我从未在bash上发送过电子邮件,但是这对于压缩超过150K的文件夹应该有效。 Hope it helps. 希望能帮助到你。

#!/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