#!/bin/bash
# 定義表名數(shù)組
tables=("表名1" "表名2" "表名3" "表名4" "表名5")
months=("01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12" )
# 循環(huán)統(tǒng)計(jì)每個(gè)表每個(gè)月占用空間大小
for table in ${tables[@]}
do
echo $table >> output.txt
for month in ${months[@]}
do
echo -n "2022${month}* " >> output.txt
hadoop fs -du -s "/user/hive/warehouse/$table/city=*/time=2022${month}*" | awk '{print $2}' | paste -s -d"+" - | bc >> output.txt
done
echo -n "202301* " >> output.txt
hadoop fs -du -s "/user/hive/warehouse/cell.db/$table/city=*/time=202301*" | awk '{print $2}' | paste -s -d"+" - | bc >> output.txt
echo -n "202302* " >> output.txt
hadoop fs -du -s "/user/hive/warehouse/cell.db/$table/city=*/time=202302*" | awk '{print $2}' | paste -s -d"+" - | bc >> output.txt
echo -n "202303* " >> output.txt
hadoop fs -du -s "/user/hive/warehouse/cell.db/$table/city=*/time=202303*" | awk '{print $2}' | paste -s -d"+" - | bc >> output.txt
echo -n "202304* " >> output.txt
hadoop fs -du -s "/user/hive/warehouse/cell.db/$table/city=*/time=202304*" | awk '{print $2}' | paste -s -d"+" - | bc >> output.txt
echo -n "202305* " >> output.txt
hadoop fs -du -s "/user/hive/warehouse/cell.db/$table/city=*/time=202305*" | awk '{print $2}' | paste -s -d"+" - | bc >> output.txt
done
- 數(shù)組tables 和 months 的定義
- for in 這種循環(huán)結(jié)構(gòu)的使用(可以有別的表達(dá)形式)
- echo 的 -n 表示不換行輸出
- >> 表示追加到文件(>是覆蓋)
- 值得注意的地方在于:一開(kāi)始使用 sh 文件名.sh 執(zhí)行文件總顯示syntax報(bào)錯(cuò),這是因?yàn)樵谙到y(tǒng)中sh被重定向(重命名)了,ls -l /bin/*sh 就可以看到具體的重定向情況,可以將sh 改用 bash或者別的方式執(zhí)行。
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-509685.html
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-509685.html
到了這里,關(guān)于Linux shell(數(shù)組-循環(huán)-echo)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!