linux服务器创建回收站机制

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值