shell脚本使用crontab做定时执行

1、编写脚本:

#!/bin/bash
if [ ! -f "/home/hadoop/shell/crontab/test" ]; then
echo "test文件不存在"
touch /home/hadoop/shell/crontab/test
else
echo “删除test文件”
rm -rf /home/hadoop/shell/crontab/test
fi
 
echo `date`
echo "hello crontab"

2、编辑/etc/crontab 文件

备注:注意时间  和文件路径

3、坐等到时更新即可

备注:查看crontab的日志记录: 地址:tail -f /var/log/cron

报错备注:

由于没有后面红色的框起来的内容,若有会报错 【mail】字符报错  所以建议保存后面的输出地址

猜你喜欢

转载自blog.csdn.net/weixin_39435629/article/details/85130697