shell for循环+传参 实现分区批量加载
--addpt.sh 添加分区脚本
#!/bin/bash
source /home/tbso/conf/set_env.sh
source /home/tbso/conf/common_tables.sh
source /home/tbso/conf/common_utils.sh
if [ $# -eq 0 ]; then
DAY_1=`date +%Y%m%d -d -1day`
elif [ $# -eq 2 ]; then
DAY_1=$1
X=$2
DAY_X=`date --date="$DAY_1 $X day ago" +%Y%m%d`
else
exit -1;
fi
$HIVE<<EOF
alter table TABLE_NAME
add partition(pt='${DAY_X}')
location '分区数据所在路径/pt=${DAY_X}/';
EOF
--调用脚本 addpt_run.sh
--添加20131002往前90天内分区
------
--双重循环
--双参数
------
#!/bin/bash
source /home/tbso/conf/set_env.sh
source /home/tbso/conf/common_tables.sh
source /home/tbso/conf/common_utils.sh
for i in {20131002..20131002}
do
for j in {1..90}
do
sh /addpt.sh 脚本所在路径/addpt.sh ${i} ${j}
done
done
我是shell小白:
1. shell循环
for...in...do...done 参考链接 http://www.myexception.cn/operating-system/509618.html
while ... do ... done until ... do ... done 不定循环
参考链接 http://linzhibin824.blog.163.com/blog/static/73557710201331565443337/ (该博客值得收藏)
2. 脚本参数
$0 = shell名称或shell脚本名称
$1 = 第一个shell参数
$9 = 第九个shell参数
$# = 位置参数的个数
"$*" = "$1 $2 $3 $4 .. $n"
"$@" = "$1" "$2" "$3" "$4" .. "$n"
$? = 最近执行的命令的退出状态
$$ = 当前shell脚本的PID
$! = 最近启动的后台作业的PID
参考链接 http://www.linuxidc.com/Linux/2012-01/52192p2.htm
浙公网安备 33010602011771号