当前位置: 技术问答>linux和unix
求解释一个*.sh文件, 看不懂.谁能帮忙解释下?
来源: 互联网 发布时间:2016-07-29
本文导语: 这段谁能看懂.. 留个MSN也行.. 实在是看不懂...... 麻烦各位了. #!/bin/sh . /home1/.conf PRINT "=========================--------------------------======" PRINT ": [stc_host_task_cnt.sh] Inesrt stc_task_cnt: HOST DATA " PRINT "; [stc_host_task_cnt.sh]...
这段谁能看懂..
留个MSN也行..
实在是看不懂...... 麻烦各位了.
#!/bin/sh
. /home1/.conf
PRINT "=========================--------------------------======"
PRINT ": [stc_host_task_cnt.sh] Inesrt stc_task_cnt: HOST DATA "
PRINT "; [stc_host_task_cnt.sh] DATE : $_DATE "
PRINT "---------------------------------------------------------"
MYSQL_EXEC="$_MYSQL_EXEC -h$_DB_SVR_DATA -u$_MYSQL_USER -p$_MYSQL_PASS -P$_MYSQL_PORT --sock=/home/mysql.sock $_MYSQL_DB --skip-column-name"
HOST_VER="manage_ver_total"
TABLE_FIELD=("(task, path, ver, job_dt, hadult_cnt, hdone_cnt, hfbid_cnt, idone_cnt, iadult_cnt, imixed_cnt, tot_cnt, cand_cnt)" );
for mid in aqimg img
do
echo ${mid}
if [ ${mid} = "aqimg" ]
then
task_cd='1'
else
task_cd='3'
fi
versions=(`echo "SELECT ver FROM $HOST_VER WHERE task=${task_cd} AND path=1;" | $MYSQL_EXEC`)
i=0
## qryset[0]=""
unset qryset
for SUFFIX in "${versions[@]}"; do
HOST_TAB="pred_${mid}_host_${SUFFIX}"
PRINT "; [stc_host_task_cnt.sh] - tbl = $HOST_TAB"
DB_QRY=" SELECT ${task_cd} AS task, 1 AS path, T2.ver, T2.date, T2.hadult_cnt, T2.hdone_cnt, T2.hfbid_cnt, T2.idone_cnt, T2.iadult_cnt, T2.imixed_cnt, T2.tot_cnt , ( SELECT count(1) FROM ${HOST_TAB} ) AS cand_cnt FROM stc_task_cnt T1 RIGHT JOIN ( SELECT '${SUFFIX}' as ver , date_format(date_3, '%Y-%m-%d') as date , SUM(CASE WHEN hctgr_3 = 1 THEN 1 ELSE 0 END) AS hadult_cnt , SUM(CASE WHEN hctgr_3 = 2 THEN 1 ELSE 0 END) AS hdone_cnt , SUM(CASE WHEN hctgr_3 =31 THEN 1 ELSE 0 END) AS hfbid_cnt , SUM(CASE WHEN ctgr_3 = 1 THEN 1 ELSE 0 END) AS idone_cnt , SUM(CASE WHEN ctgr_3 = 2 THEN 1 ELSE 0 END) AS iadult_cnt , SUM(CASE WHEN ctgr_3 =99 THEN 1 ELSE 0 END) AS imixed_cnt , SUM(CASE WHEN hctgr_3 IN ( 1, 2, 31) THEN 1 ELSE 0 END) AS tot_cnt FROM ${HOST_TAB} WHERE ctgr_3 > 0 GROUP BY 2) T2 ON T1.task=${task_cd} AND T1.path=1 AND T1.ver = T2.ver AND T1.job_dt = T2.date"
if [ $i -gt 0 ]
then
DB_QRY=`echo " UNION ALL $DB_QRY"`
fi
i=`expr $i + 1`
qryset[$i]=$DB_QRY
done
$MYSQL_EXEC -e "INSERT INTO stc_task_cnt ${TABLE_FIELD} ${qryset[*]} ON DUPLICATE KEY UPDATE hadult_cnt = values(hadult_cnt) , hdone_cnt = values(hdone_cnt) , hfbid_cnt = values(hfbid_cnt) , idone_cnt = values(idone_cnt) , iadult_cnt = values(iadult_cnt) , imixed_cnt = values(imixed_cnt) , tot_cnt = values(tot_cnt)"
if [ $? -ne 0 ]
then
PRINT "; [stc_host_task_cnt.sh] [ERROR] SELECT ERROR ${HOST_TAB}";
exit -1;
else
PRINT "; [stc_host_task_cnt.sh] [DONE]"
fi
done
PRINT "=================== FINISHED ====================="
留个MSN也行..
实在是看不懂...... 麻烦各位了.
#!/bin/sh
. /home1/.conf
PRINT "=========================--------------------------======"
PRINT ": [stc_host_task_cnt.sh] Inesrt stc_task_cnt: HOST DATA "
PRINT "; [stc_host_task_cnt.sh] DATE : $_DATE "
PRINT "---------------------------------------------------------"
MYSQL_EXEC="$_MYSQL_EXEC -h$_DB_SVR_DATA -u$_MYSQL_USER -p$_MYSQL_PASS -P$_MYSQL_PORT --sock=/home/mysql.sock $_MYSQL_DB --skip-column-name"
HOST_VER="manage_ver_total"
TABLE_FIELD=("(task, path, ver, job_dt, hadult_cnt, hdone_cnt, hfbid_cnt, idone_cnt, iadult_cnt, imixed_cnt, tot_cnt, cand_cnt)" );
for mid in aqimg img
do
echo ${mid}
if [ ${mid} = "aqimg" ]
then
task_cd='1'
else
task_cd='3'
fi
versions=(`echo "SELECT ver FROM $HOST_VER WHERE task=${task_cd} AND path=1;" | $MYSQL_EXEC`)
i=0
## qryset[0]=""
unset qryset
for SUFFIX in "${versions[@]}"; do
HOST_TAB="pred_${mid}_host_${SUFFIX}"
PRINT "; [stc_host_task_cnt.sh] - tbl = $HOST_TAB"
DB_QRY=" SELECT ${task_cd} AS task, 1 AS path, T2.ver, T2.date, T2.hadult_cnt, T2.hdone_cnt, T2.hfbid_cnt, T2.idone_cnt, T2.iadult_cnt, T2.imixed_cnt, T2.tot_cnt , ( SELECT count(1) FROM ${HOST_TAB} ) AS cand_cnt FROM stc_task_cnt T1 RIGHT JOIN ( SELECT '${SUFFIX}' as ver , date_format(date_3, '%Y-%m-%d') as date , SUM(CASE WHEN hctgr_3 = 1 THEN 1 ELSE 0 END) AS hadult_cnt , SUM(CASE WHEN hctgr_3 = 2 THEN 1 ELSE 0 END) AS hdone_cnt , SUM(CASE WHEN hctgr_3 =31 THEN 1 ELSE 0 END) AS hfbid_cnt , SUM(CASE WHEN ctgr_3 = 1 THEN 1 ELSE 0 END) AS idone_cnt , SUM(CASE WHEN ctgr_3 = 2 THEN 1 ELSE 0 END) AS iadult_cnt , SUM(CASE WHEN ctgr_3 =99 THEN 1 ELSE 0 END) AS imixed_cnt , SUM(CASE WHEN hctgr_3 IN ( 1, 2, 31) THEN 1 ELSE 0 END) AS tot_cnt FROM ${HOST_TAB} WHERE ctgr_3 > 0 GROUP BY 2) T2 ON T1.task=${task_cd} AND T1.path=1 AND T1.ver = T2.ver AND T1.job_dt = T2.date"
if [ $i -gt 0 ]
then
DB_QRY=`echo " UNION ALL $DB_QRY"`
fi
i=`expr $i + 1`
qryset[$i]=$DB_QRY
done
$MYSQL_EXEC -e "INSERT INTO stc_task_cnt ${TABLE_FIELD} ${qryset[*]} ON DUPLICATE KEY UPDATE hadult_cnt = values(hadult_cnt) , hdone_cnt = values(hdone_cnt) , hfbid_cnt = values(hfbid_cnt) , idone_cnt = values(idone_cnt) , iadult_cnt = values(iadult_cnt) , imixed_cnt = values(imixed_cnt) , tot_cnt = values(tot_cnt)"
if [ $? -ne 0 ]
then
PRINT "; [stc_host_task_cnt.sh] [ERROR] SELECT ERROR ${HOST_TAB}";
exit -1;
else
PRINT "; [stc_host_task_cnt.sh] [DONE]"
fi
done
PRINT "=================== FINISHED ====================="
|
MYSQL_EXEC="$_MYSQL_EXEC -h$_DB_SVR_DATA -u$_MYSQL_USER -p$_MYSQL_PASS -P$_MYSQL_PORT --sock=/home/mysql.sock $_MYSQL_DB --skip-column-name"
//给变量MYSQL_EXEC赋值,${xxx}或者$xxx就是引用变量xxx的值,下面也一样
HOST_VER="manage_ver_total"
给HOST_VER赋值
TABLE_FIELD=("(task, path, ver, job_dt, hadult_cnt, hdone_cnt, hfbid_cnt, idone_cnt, iadult_cnt, imixed_cnt, tot_cnt, cand_cnt)" );
给TABLE_FIELD赋值
for mid in aqimg img //for循环,2次,mid==aqimg,mid==img
do
echo ${mid} //输出mid的值
if [ ${mid} = "aqimg" ] //判断语句,如果mid的值等于"aqimg"成立
then
task_cd='1' //if条件成立,task_cd='1'
else
task_cd='3' //if条件不成立,task_cd='3'
fi
versions=(`echo "SELECT ver FROM $HOST_VER WHERE task=${task_cd} AND path=1;" | $MYSQL_EXEC`)
//把echo "SELECT ver FROM $HOST_VER WHERE task=${task_cd} AND path=1;" | $MYSQL_EXEC执行的结果赋给变量versions
i=0
## qryset[0]=""
unset qryset //清除变量qryset
for SUFFIX in "${versions[@]}"; do //又是循环,循环${versions[@]},有几个元素就循环几次
HOST_TAB="pred_${mid}_host_${SUFFIX}" //给HOST_TAB赋值
PRINT "; [stc_host_task_cnt.sh] - tbl = $HOST_TAB" //应该是显示引号内容
DB_QRY=" SELECT ${task_cd} AS task, 1 AS path, T2.ver, T2.date, T2.hadult_cnt, T2.hdone_cnt, T2.hfbid_cnt, T2.idone_cnt, T2.iadult_cnt, T2.imixed_cnt, T2.tot_cnt , ( SELECT count(1) FROM ${HOST_TAB} ) AS cand_cnt FROM stc_task_cnt T1 RIGHT JOIN ( SELECT '${SUFFIX}' as ver , date_format(date_3, '%Y-%m-%d') as date , SUM(CASE WHEN hctgr_3 = 1 THEN 1 ELSE 0 END) AS hadult_cnt , SUM(CASE WHEN hctgr_3 = 2 THEN 1 ELSE 0 END) AS hdone_cnt , SUM(CASE WHEN hctgr_3 =31 THEN 1 ELSE 0 END) AS hfbid_cnt , SUM(CASE WHEN ctgr_3 = 1 THEN 1 ELSE 0 END) AS idone_cnt , SUM(CASE WHEN ctgr_3 = 2 THEN 1 ELSE 0 END) AS iadult_cnt , SUM(CASE WHEN ctgr_3 =99 THEN 1 ELSE 0 END) AS imixed_cnt , SUM(CASE WHEN hctgr_3 IN ( 1, 2, 31) THEN 1 ELSE 0 END) AS tot_cnt FROM ${HOST_TAB} WHERE ctgr_3 > 0 GROUP BY 2) T2 ON T1.task=${task_cd} AND T1.path=1 AND T1.ver = T2.ver AND T1.job_dt = T2.date"
//给DB_QRY赋值
if [ $i -gt 0 ] //又是判断语句,如何变量i的值大于0则成立
then
DB_QRY=`echo " UNION ALL $DB_QRY"` //条件成立,把echo " UNION ALL $DB_QRY"赋给DB_QRY
fi
i=`expr $i + 1` //相当于别的语言i++
qryset[$i]=$DB_QRY //把DB_QRY的值付给数组元素qryset[$i]
done
$MYSQL_EXEC -e "INSERT INTO stc_task_cnt ${TABLE_FIELD} ${qryset[*]} ON DUPLICATE KEY UPDATE hadult_cnt = values(hadult_cnt) , hdone_cnt = values(hdone_cnt) , hfbid_cnt = values(hfbid_cnt) , idone_cnt = values(idone_cnt) , iadult_cnt = values(iadult_cnt) , imixed_cnt = values(imixed_cnt) , tot_cnt = values(tot_cnt)"
//这一句应该是在执行mysql的操作
if [ $? -ne 0 ] //判断上一个操作是否成功,
then
//$? -ne 0成立,即上一个操作退出状态非0,即上一个操作执行错误
PRINT "; [stc_host_task_cnt.sh] [ERROR] SELECT ERROR ${HOST_TAB}";
//应该是显示信息
exit -1; //以执行结果-1退出脚本
else
//$? -ne 0不成立,即上一个操作退出状态为0,即上一个操作执行成功
PRINT "; [stc_host_task_cnt.sh] [DONE]"
//输出信息
fi
done
感觉你给的代码也不全 我这会也有点忙 所以大概解释了一下
//给变量MYSQL_EXEC赋值,${xxx}或者$xxx就是引用变量xxx的值,下面也一样
HOST_VER="manage_ver_total"
给HOST_VER赋值
TABLE_FIELD=("(task, path, ver, job_dt, hadult_cnt, hdone_cnt, hfbid_cnt, idone_cnt, iadult_cnt, imixed_cnt, tot_cnt, cand_cnt)" );
给TABLE_FIELD赋值
for mid in aqimg img //for循环,2次,mid==aqimg,mid==img
do
echo ${mid} //输出mid的值
if [ ${mid} = "aqimg" ] //判断语句,如果mid的值等于"aqimg"成立
then
task_cd='1' //if条件成立,task_cd='1'
else
task_cd='3' //if条件不成立,task_cd='3'
fi
versions=(`echo "SELECT ver FROM $HOST_VER WHERE task=${task_cd} AND path=1;" | $MYSQL_EXEC`)
//把echo "SELECT ver FROM $HOST_VER WHERE task=${task_cd} AND path=1;" | $MYSQL_EXEC执行的结果赋给变量versions
i=0
## qryset[0]=""
unset qryset //清除变量qryset
for SUFFIX in "${versions[@]}"; do //又是循环,循环${versions[@]},有几个元素就循环几次
HOST_TAB="pred_${mid}_host_${SUFFIX}" //给HOST_TAB赋值
PRINT "; [stc_host_task_cnt.sh] - tbl = $HOST_TAB" //应该是显示引号内容
DB_QRY=" SELECT ${task_cd} AS task, 1 AS path, T2.ver, T2.date, T2.hadult_cnt, T2.hdone_cnt, T2.hfbid_cnt, T2.idone_cnt, T2.iadult_cnt, T2.imixed_cnt, T2.tot_cnt , ( SELECT count(1) FROM ${HOST_TAB} ) AS cand_cnt FROM stc_task_cnt T1 RIGHT JOIN ( SELECT '${SUFFIX}' as ver , date_format(date_3, '%Y-%m-%d') as date , SUM(CASE WHEN hctgr_3 = 1 THEN 1 ELSE 0 END) AS hadult_cnt , SUM(CASE WHEN hctgr_3 = 2 THEN 1 ELSE 0 END) AS hdone_cnt , SUM(CASE WHEN hctgr_3 =31 THEN 1 ELSE 0 END) AS hfbid_cnt , SUM(CASE WHEN ctgr_3 = 1 THEN 1 ELSE 0 END) AS idone_cnt , SUM(CASE WHEN ctgr_3 = 2 THEN 1 ELSE 0 END) AS iadult_cnt , SUM(CASE WHEN ctgr_3 =99 THEN 1 ELSE 0 END) AS imixed_cnt , SUM(CASE WHEN hctgr_3 IN ( 1, 2, 31) THEN 1 ELSE 0 END) AS tot_cnt FROM ${HOST_TAB} WHERE ctgr_3 > 0 GROUP BY 2) T2 ON T1.task=${task_cd} AND T1.path=1 AND T1.ver = T2.ver AND T1.job_dt = T2.date"
//给DB_QRY赋值
if [ $i -gt 0 ] //又是判断语句,如何变量i的值大于0则成立
then
DB_QRY=`echo " UNION ALL $DB_QRY"` //条件成立,把echo " UNION ALL $DB_QRY"赋给DB_QRY
fi
i=`expr $i + 1` //相当于别的语言i++
qryset[$i]=$DB_QRY //把DB_QRY的值付给数组元素qryset[$i]
done
$MYSQL_EXEC -e "INSERT INTO stc_task_cnt ${TABLE_FIELD} ${qryset[*]} ON DUPLICATE KEY UPDATE hadult_cnt = values(hadult_cnt) , hdone_cnt = values(hdone_cnt) , hfbid_cnt = values(hfbid_cnt) , idone_cnt = values(idone_cnt) , iadult_cnt = values(iadult_cnt) , imixed_cnt = values(imixed_cnt) , tot_cnt = values(tot_cnt)"
//这一句应该是在执行mysql的操作
if [ $? -ne 0 ] //判断上一个操作是否成功,
then
//$? -ne 0成立,即上一个操作退出状态非0,即上一个操作执行错误
PRINT "; [stc_host_task_cnt.sh] [ERROR] SELECT ERROR ${HOST_TAB}";
//应该是显示信息
exit -1; //以执行结果-1退出脚本
else
//$? -ne 0不成立,即上一个操作退出状态为0,即上一个操作执行成功
PRINT "; [stc_host_task_cnt.sh] [DONE]"
//输出信息
fi
done
感觉你给的代码也不全 我这会也有点忙 所以大概解释了一下