linux下ビッグデータ人工知能自動化スクリプトタイミングタスクテンプレート
2852 ワード
本稿では,初級sqlおよびpython人工知能開発の基礎があり,タイミングタスクを実行する必要がある初学者について述べる.
import sys
print(sys.path)
kinit -kt/home/accunt/cluster_keytab/accunt.keytab accuntの中のaccuntはあなたの自分の口座で、この言葉がなければ、プログラムも間違っています.そのため、このコマンドを数時間おきに実行するタイミングタスクを書くことをお勧めします.
テンプレートの内容は次のとおりです.
!/bin/bash
kinit -kt/home/accunt/cluster_keytab/accunt.keytab accunt
echo “*****************”
train_month_t=$(date +%Y%m -d ‘-1 month’)
echo $train_month_t
echo “********start********”
sql_train=”
create table if not exists test.t_test
(a string,
b string)
row format delimited fields terminated by ‘\t’
lines terminated by ‘’
stored as textfile;
set hive.exec.dynamic.partition.mode=nonstrict;
insert overwrite table test.t_test
select a,b
from product.t_test
where day=concat(‘$train_month_t’,’01’);
“
echo $sql_train >./train.sql
kinit -kt/home/accunt/cluster_keytab/accunt.keytab accunt
hive -f ./train.sql
export HIVE_SKIP_SPARK_ASSEMBLY=true;
hive -e “set hive.cli.print.header=true;
select distinct a,b from test.t_test;” >./train.csv
echo “********train sql successful*******”
kinit -kt/home/accunt/cluster_keytab/accunt.keytab accunt
./python ./train_pred.py $py_month
echo “********py successful*******”
load_sql=”
create table if not exists test.result
(a string,
b string)
partitioned by (month string)
row format delimited fields terminated by ‘\t’
lines terminated by ‘’
stored as textfile
tblproperties(‘skip.header.line.count’=’1’);
LOAD DATA LOCAL INPATH ‘./preds_$load_month.csv’
into table test.result PARTITION (month=’$load_month’);
“
echo $load_sql>./load.sql
kinit -kt/home/accunt/cluster_keytab/accunt.keytab accunt
hive -f ./load.sql
echo “********load_sql successful*******”
echo “********successful*******”
, , :
、 ;
、 hive , ;
、 python , , , ;
、 , ,
( )、 crontab, 。 , shell python , python , , 。 , python test.py。
import sys
print(sys.path)
python test.py crontab -e , 。 , ,
kinit -kt/home/accunt/cluster_keytab/accunt.keytab accuntの中のaccuntはあなたの自分の口座で、この言葉がなければ、プログラムも間違っています.そのため、このコマンドを数時間おきに実行するタイミングタスクを書くことをお勧めします.
( )、 , , ,train_month_t=$(date +%Y%m -d '-1 month') , ,‘$’ , $train_month_t sql 。exportHIVE_SKIP_SPARK_ASSEMBLY=true; , 。
( )、 shell , python 。 ,python , python 。 sys.argv[1] $py_month 。 '201808', 。
( )、 , , 。
テンプレートの内容は次のとおりです.
!/bin/bash
kinit -kt/home/accunt/cluster_keytab/accunt.keytab accunt
echo “*****************”
train_month_t=$(date +%Y%m -d ‘-1 month’)
echo $train_month_t
echo “********start********”
sql_train=”
create table if not exists test.t_test
(a string,
b string)
row format delimited fields terminated by ‘\t’
lines terminated by ‘’
stored as textfile;
set hive.exec.dynamic.partition.mode=nonstrict;
insert overwrite table test.t_test
select a,b
from product.t_test
where day=concat(‘$train_month_t’,’01’);
“
echo $sql_train >./train.sql
kinit -kt/home/accunt/cluster_keytab/accunt.keytab accunt
hive -f ./train.sql
export HIVE_SKIP_SPARK_ASSEMBLY=true;
hive -e “set hive.cli.print.header=true;
select distinct a,b from test.t_test;” >./train.csv
echo “********train sql successful*******”
kinit -kt/home/accunt/cluster_keytab/accunt.keytab accunt
./python ./train_pred.py $py_month
echo “********py successful*******”
load_sql=”
create table if not exists test.result
(a string,
b string)
partitioned by (month string)
row format delimited fields terminated by ‘\t’
lines terminated by ‘’
stored as textfile
tblproperties(‘skip.header.line.count’=’1’);
LOAD DATA LOCAL INPATH ‘./preds_$load_month.csv’
into table test.result PARTITION (month=’$load_month’);
“
echo $load_sql>./load.sql
kinit -kt/home/accunt/cluster_keytab/accunt.keytab accunt
hive -f ./load.sql
echo “********load_sql successful*******”
echo “********successful*******”
, , , , !