创建定时任务
/var/spool/cron/root(账号=文件名)
0 3 * * * sh /root/clearCache.sh 每天3点执行
*/2 * * * * sh /root/clearCache.sh 每两分钟执行
每五分钟执行一次: */5 * * * *
每小时执行一次 : 0 * * * *
每天执行一次: 0 0 * * *
每周执行一次: 0 0 * * 0
每月执行一次: 0 0 1 * *
每年执行一次: 0 0 1 1 *
clearCache.sh clearwork.out 会是同目录输出,且需要777权限
#!/bin/sh
sync
sleep 1
echo $(date "+%Y-%m-%d %H:%M:%S")"@ sync_ok" >> clearwork.out
echo 1 > /proc/sys/vm/drop_caches
sleep 30
echo $(date "+%Y-%m-%d %H:%M:%S")"@ 1_ok" >> clearwork.out
echo 2 > /proc/sys/vm/drop_caches
sleep 10
echo $(date "+%Y-%m-%d %H:%M:%S")"@ 2_ok" >> clearwork.out
echo 3 > /proc/sys/vm/drop_caches
sleep 10
echo $(date "+%Y-%m-%d %H:%M:%S")"@ 3_ok" >> clearwork.out
$(date "+%Y-%m-%d %H:%M:%S") 取得当前时间
>> clearwork.out 为文件内最后追加
> clearwork.out 为覆盖