Hive 在 Linux 的 Shell 中的使用、在shell脚本中获取Linux系统当前日期时间、用 sed 的修改结果直接修改读取数据的文件、添加并开启定时任务
Hive 在 Linux 的 Shell 中的使用
第一种:
hive -e "后面直接加一条SQL"
hive -e "select * from test1.students limit 10"
第二种:
hive -f hql文件路径
将HQL写在一个文件里,再使用 -f 参数指定该文件
编辑 .sh 脚本文件
在shell脚本中获取Linux系统当前日期时间
time=$(date "+%Y-%m-%d %H:%M:%S")
sed -i "s/A/B/" 文件名用 sed 的修改结果直接修改读取数据的文件,而不是由屏幕输出动作A -- 需要被修改的数据
B -- 修改内容
# 例如
# hql.sh文件 -- hive -e
#!/bin/sh
#date="2022-02-22"
date=$(date "+%Y-%m-%d")
sql1="select * from students_pt where pt='${date}'"
hive -e ${sql1}
echo $sql1
# hql.sh文件 -- hive -f
#!/bin/sh
#date="2022-02-22"
date=$(date "+%Y%m%d")
sed -i "s/!everydate!/${date}/" /usr/local/soft/scripts/stu_pt.sql
cat /usr/local/soft/scripts/stu_pt.sql
hive -f /usr/local/soft/scripts/stu_pt.sql
sed -i "s/${date}/!everydate!/" /usr/local/soft/scripts/stu_pt.sql
cat /usr/local/soft/scripts/stu_pt.sql
// stu_pt.sql -- SQL文件
select * from test1.students_pt1 where pt='!everydate!';
添加定时任务
具体内容参考shell编程学习笔记中的
定时器注意
xxx.sh需要有可执行权限添加执行权限
chmod a+x 文件名
通过crontab -e添加定时任务
:wq 即 添加 并 开启定时任务
// 将输出结果重定向
*(分) *(时) *(星期) *(几号) *(月份) /xxx.sh >> /xxx
// 例如 保存 :wq 即会开启定时任务
*/1 * * * * /usr/local/soft/scripts/hql.sh >> /usr/local/soft/scripts/logs/1

浙公网安备 33010602011771号