1.传脚本文件remove.sh到/bin/remove.sh,注意权限
2.echo 'alias rm=/bin/remove.sh'>>/etc/bashrc
3.source /etc/bashrc
4.创建回收站目录并赋权
5.配置计划任务定时清理回收站
playbook
---
- hosts: all
remote_user: root
tasks:
- name: copy script
copy: src=/root/remove.sh dest=/bin/ backup=yes mode=755
- name: add PATH
shell: echo "alias rm=/bin/remove.sh">>/etc/bashrc && source /etc/bashrc
- name: add recycle_dir
file: name=/data/.recycle state=directory
- name: change mode for recycle_dir
file: name=/data/.recycle mode=777
- name: add crontab to clear recycle
cron: name=clear_recycle minute=1 hour=1 job='find /data/.recycle/ -mtime +2 -delete' user=root
remove.sh
#!/bin/bash
time=`date +%F_%H:%M:%S`
dir=/data/.recycle
#将删除的文件转移到回收站
for file in $@
do
#过滤掉rm的-rf参数
if [[ "$file" =~ ^-[rf]+$ ]]; th
linux服务器创建回收站机制
最新推荐文章于 2022-08-23 13:49:45 发布