目录
3.加入开机自动启动: chkconfig –level 35 crond on 或chkconfig crond on
第4-7每一步必不可少写
1.安装crontab
yum install vixie-cron
yum install crontab
2.启动crontab服务
用以下的方法启动、关闭这个cron服务:
systemctl start crond //启动服务
systemctl stop crond //关闭服务
systemctl restart crond //重启服务
systemctl reload crond //重新载入配置
查看crontab运行状态
service crond status
3.加入开机自动启动:
chkconfig –level 35 crond on 或chkconfig crond on
4.编写脚本
touch /data/influxdb/influxdb_earthsite_crontab.sh
vi/data/influxdb/influxdb_earthsite_crontab.sh
#! /bin/bash 是必须要写的,表示要是/bin/bash这个执行脚本的命令执行接下来写的脚本,
influxd backup -database earthsite /tmp/backup表示备份influxdb数据库earthsite 到/tmp/backup文件夹下面
注意:不要用xftp修改文件,粘贴什么的,回车一下就会多一个字符从而影响执行,表面看不到,但是用xshell的vi打开就看到了
脚本编写完成后,.通过chmod命令赋予该脚本的执行权限chmod 777 sq.sh,否则没有执行权限
5.添加任务调度
crontab -e进入添加页面,不要vi /etc/crontab,因为crontab -e是在当前用户下配置你的定时任务,你写进去的会自动写入相应的crontab配置文件
添加*/1 * * * * /data/influxdb/influxdb_earthsite_crontab.sh 表示每分钟执行一次脚本
时间保存策略:
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
每天(凌晨
4
:
00
)执行/etc/cron.daily内的脚本
00
4
* * * root
/data/influxdb/influxdb_earthsite_crontab.sh
每星期(周日凌晨
4
:30
)执行/etc/cron.weekly内的脚本
30 4
* *
0
root
/data/influxdb/influxdb_earthsite_crontab.sh
30 4 * * 0 /data/influxdb/influxdb_earthsite_crontab.sh
6.crontab -l 查看已经添加的任务调度
7.重启任务调度服务开始执行任务调度
systemctl restart crond