常见的一些shell脚本书写,定时删除,压缩备份

删除与备份videoportal日志

  1. 写执行删除过期日志的shell脚本

以下参考文档:https://blog.csdn.net/yuan882696yan/article/details/77885339

执行删除 /home/test/REPORT/send/videoportal23890234823904.txt这个目录下文档(当前是保留五天日志)

定时任务执行这个目录下的shell脚本:   /home/myshell/test.sh  (需要进行赋权操作chmod +x test.sh)

可以使用  ./test.sh 这个命令来验证是否生效

2.设置定时器任务使用cron方式

以下参考文档:https://www.cnblogs.com/kxdblog/p/4211940.html

使用crontab定时任务这个工具执行上述shell脚本

使用命令:vim /etc/crontab   在其文档之后添加   01 20 * * * root /home/myshell/test.sh

 

重新加载配置

命令:/sbin/service crond reload

重启cron

命令:/sbin/service crond restart

启动cron

命令:service crond start

Ps:上述一些启动与重启也参考下面的链接

3.设置开机自启

以下参考文档:https://blog.csdn.net/u012569217/article/details/78909309(很重要)

cron并不是开机自启的,需要配置开机自动启动

开机自动启动:systemctl enable crond.service

附加:验证crontab是否安装https://www.cnblogs.com/zoulongbin/p/6187238.html  (此处未验证,貌似可以忽略)

备份并压缩日志

  1. 参考:https://blog.csdn.net/qq_36746815/article/details/83141679

linux默认没有zip与unzip软件需要安装

         安装zip和unzip命令:

#yum list | grep zip/unzip 

#yum install zip

#yum install unzip

  1. 参考:https://zhidao.baidu.com/question/1861238026303254827.html

https://blog.csdn.net/liyyzz33/article/details/84775376

https://www.runoob.com/linux/linux-shell-echo.html

shell写法参考上述文档

备份与压缩的shell所在目录是:

/home/video/REPORT/bak.sh

         以上shell作用是保留昨日的日志文件内容并压缩备份到

         /home/video/REPORT/backup这个目录下

原文地址:https://www.cnblogs.com/chaojibaidu/p/10861945.html