附加一个稍微完成的例子,该例子是要事先判断该job是否已经跑过(跑过的话会写入日志表tb_kettle_finish_info),跑过的话就不跑。 [etl@node1 shell]$ more sql_to_oracle.sh #!/bin/bash l_last_date=`date +%Y%m%d --date="1 day ago"` sqlplus /nolog< whenever sqlerror exit 20; whenever oserror exit 20; connect hxl/hxl; variable cnt number; begin select Count(1) into :cnt from tb_kettle_finish_info t where t.statedate=${l_last_date} ; if :cnt = 0 then :cnt:=0; else :cnt:=99; end if; end; / exit :cnt ENDOFINPUT flag=$? echo $flag
if [ ${flag} = 0 ]; then ##go to kettle soft dir cd /opt/pdi-ce-4.4.0-stable/data-integration ./kitchen.sh -rep dev_my_etl -user admin -pass admin -dir /mssql_to_oracel -job jb_sqlserver_to_oracle_for_tb_test -level=basic -par am:pi_statedate=${l_last_date} >/home/etl/log/kettle_${l_last_date}.log fi
如上例子的另外一种写法 [etl@node1 shell]$ more sql_to_oracle01.sh #!/bin/bash l_last_date=`date +%Y%m%d --date="1 day ago"` sqlplus /nolog< whenever sqlerror exit 20; whenever oserror exit 20; connect hxl/hxl; col coun new_value v_coun; select Count(1) coun from tb_kettle_finish_info t where t.statedate=${l_last_date} ; exit v_coun / ENDOFINPUT flag="$?"
if [ ${flag} = 0 ]; then ##go to kettle soft dir cd /opt/pdi-ce-4.4.0-stable/data-integration ./kitchen.sh -rep dev_my_etl -user admin -pass admin -dir /mssql_to_oracel -job jb_sqlserver_to_oracle_for_tb_test -level=basic -par am:pi_statedate=${l_last_date} >/home/etl/log/kettle_${l_last_date}.log fi