CentOS7下crontab简单使用
- 安装
#!/bin/bash
# 安装
yum -y install crontabs
# 启动
systemctl start crond
# 开机启动
chkconfig --level 345 crond on
- 测试脚本, append.sh
#!/bin/bash
# import env
. /etc/profile
. ~/.bash_profile
# jdk
jdk=`java -version`
echo $jdk >> /root/date.txt
# procedure
args=$1
yesterday_time=`date "+%Y%m%d_%H%M" -d "-1 days"`
echo "${args} : ${yesterday_time}" >> /root/date.txt
- 测试crontab功能
# 编辑任务命令
crontab -e
# 新增任务
# 每分钟执行一次(目前测试, testAgrs 需要是简单文本参数, `` "" ''等符号处理的数据无法识别
*/1 * * * * /root/append.sh testAgrs >> /root/date.txt 2>&1
# 编辑完成后重启
systemctl restart crond