!/bin/bash dir="/home/face/capturepic/2017/" Available=`df -k | sed -n '/sda3/p' | awk '{print int($5)}'` if [ $Available -gt 10 ];then echo "available less 10 " for mou in `ls $dir` do tmou=date +%m if [ $mou -lt $tmou ];then echo "delete dir $dir$mou " rm -rf $dir$mou elif [ $mou -eq $tmou ];then for day in `ls $dir$mou/` do today=date +%d if [ $day -ne $today ];then echo "delete dir $dir$tmou/$day " rm -rf $dir$tmou/$day fi done fi done fi
root@u3-server:/home/u3/mjl# tail /var/log/cron.log Oct 15 11:32:01 u3-server CRON[15159]: (root) CMD (/home/u3/mjl/watchdog.sh) Oct 15 11:32:01 u3-server CRON[15158]: (CRON) info (No MTA installed, discarding output) Oct 15 11:33:01 u3-server CRON[15293]: (root) CMD (/home/u3/mjl/watchdog.sh) Oct 15 11:33:01 u3-server CRON[15292]: (CRON) info (No MTA installed, discarding output) Oct 15 11:34:01 u3-server CRON[15427]: (root) CMD (/home/u3/mjl/watchdog.sh) Oct 15 11:34:01 u3-server CRON[15426]: (CRON) info (No MTA installed, discarding output) Oct 15 11:35:01 u3-server CRON[15561]: (root) CMD (/home/u3/mjl/watchdog.sh) Oct 15 11:35:01 u3-server CRON[15560]: (CRON) info (No MTA installed, discarding output) Oct 15 11:36:01 u3-server CRON[15695]: (root) CMD (/home/u3/mjl/watchdog.sh) Oct 15 11:36:01 u3-server CRON[15694]: (CRON) info (No MTA installed, discarding output)
u3@u3-server:~/mjl$ cat /etc/rc.local #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. service cron start exit 0