Linux下crontab命令添加Kettle作业定时任务

1. 确保作业 $KETTLE_HOME/kitchen.sh -file=/data1/testdata/testkjb.kjb 或转换 $KETTLE_HOME/pan.sh -file=/data1/testdata/testktr.ktr 能在Linux下正常执行

此步骤在JDK配置正确,(Ps.可选择配置Kettle的环境变量,主要是定位程序所在主目录,不用每次引用绝对路径),

当前用户拥有对应*.sh文件有执行权限的情况下,很少有其它问题。

2.编写执行Kettle作业或转换的execron.sh脚本,此处特别要注意红色标注部分,Shell脚本里面要执行一下刷新当前系统环境变量的操作,

因为crontab命令执行脚本时不会读取当前的环境变量

#!/bin/bash

source /etc/profile

#$KETTLE_HOME/pan.sh -file=/data1/testdata/testktr.ktr

$KETTLE_HOME/kitchen.sh -file=/data1/testdata/testkjb.kjb

3. crontab -e 进入定时任务编辑文件,命令格式见下方:

# 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

分 时 日 月 周 命令

第1列表示分钟1~59 每分钟用*或者 */1表示

第2列表示小时1~23(0表示0点)

第3列表示日期1~31

第4列表示月份1~12

第5列标识号星期0~6(0表示星期天)

第6列要运行的命令

例如:每天早上7:50执行一次execron.sh

50 7 * * * /data1/testdata/execron.sh

详细执行命令解释请参考百度百科:

crontab命令_百度百科