alert_DBA102.log: ASCII English text
alert_DBA102.log.Z: ASCII text (compress’d data 16 bits)
dba102_asmb_12307.trc.Z: ASCII English text (compress’d data 16 bits)
dba102_asmb_20653.trc.Z: ASCII English text (compress’d data 16 bits)
由于我们只对文件名感兴趣,因此我们应用下一个命令 cut -d":" -f1,仅显示第一个字段:
alert_DBA102.log
alert_DBA102.log.Z
dba102_asmb_12307.trc.Z
dba102_asmb_20653.trc.Z
目前,我们希望使用 ls -l 命令,将上述列表作为参数进行传递,一次传递一个。xargs 命令允许你这样做。最后一部分,xargs ls -ltr,用于接收输出并对其执行 ls -ltr 命令,如下所示:
ls -ltr alert_DBA102.log
ls -ltr alert_DBA102.log.Z
ls -ltr dba102_asmb_12307.trc.Z
ls -ltr dba102_asmb_20653.trc.Z
因此,xargs 本身虽然没有多大用处,但在和其他命令相结合时,他的功能非常强大。
下面是另一个示例,我们希望计算这些文件中的行数:
例 2:
for (( l_index=0; l_index < ${#l_server_ip_list[*]}; l_index++ ))
do
l_tmp_ip=${l_server_ip_list[l_index]}
l_tmp_pwd=${l_server_pwd_list[l_index]}
for l_db in $(grep "DB_.*_IP[[:space:]]*=[[:space:]]*${l_tmp_ip}" $silence_conf | awk -F_ '{print $2}')
do
tmp_value=$(read_file $silence_conf "DB_${l_db}_ENABLE")
tmp_value=$(trim_space "$tmp_value" "lrs")
if [ "$tmp_value" == "1" ]; then
#build_expect_file "${l_tmp_ip}" "${l_tmp_pwd}" "cat /etc/issue | grep 'SUSE' | awk '{print \"SYS_RESULT:\" \$7,\$9}'"
build_expect_file "${l_tmp_ip}" "${l_tmp_pwd}" "cat /etc/issue | grep 'SUSE'"
/usr/bin/expect -f expect.tmp >./sys_info.tmp
rm -f expect.tmp
l_tmp=$(grep "Welcome to SUSE" ./sys_info.tmp | awk '{if ( $0 ~ /10.*\(x86_64\)/ ) print 0; else print 1}')
rm -f ./sys_info.tmp
if [ "$l_tmp" != "0" ]; then
# 首次出现检查出异常需要换行输出
if [ ${l_has_err} -eq 0 ]; then
echo ""
fi
l_has_err=1
#echo "The DB SERVER ${l_tmp_ip} is not 64bit SuSE10 system!"
cfont -red "The system should be SuSE10(64 bit) on ${l_tmp_ip} where the ${l_db} DB is installed." -reset
echo ""
l_system_version=1
#exit 1
fi
break;
fi
done
done
if [ ${l_system_version} -eq 1 ]; then
exit 1
fi 作者: liuxin0619 时间: 2011-12-22 16:13
1. DB_MODLUE_LIST=(SIG P2P NETS AFC VOIP SUF MOBILE)
DB_MODLUE_NUM="${#DB_MODLUE_LIST[*]}"
l_check_url_version_flg=1
while [ $l_check_url_version_flg -eq 1 ]
do
if [ -f ${PACKAGE_DIR}/url_version.txt ]
then
dos2unix ${PACKAGE_DIR}/url_version.txt > /dev/null 2>&1
local l_url_version=`sed -n '1p' ${PACKAGE_DIR}/url_version.txt | awk -F= '{print $2}' |cut -c 0-11`
l_check_url_version_flg=0
else
echo "==========================================================================================="
echo " **********************Warning********************** "
echo " ** The ${PACKAGE_DIR}/url_version.txt file does not exist."
eval "echo ' ** The ${PACKAGE_DIR}/url_version.txt file does not exist.' ${TOLOG}"
echo " ** Please make sure the ${PACKAGE_DIR}/url_version.txt file exists."
echo "==========================================================================================="
user_confirm "Please confirm whether to send this file again"
fi
done
function user_confirm()
{
local l_in_message="$1"
local l_not_exit_flg="$2"
while true
do
#echo -ne "Please confirm whether to install?(y or n)"
echo -ne "${l_in_message}? (y or n): "
read install_yes
case $install_yes in
y|Y|yes|YES)
break
;;
n|N|no|NO)
if [ "${l_not_exit_flg}" = "1" ]
then
return 1
else
exit 0
fi
;;
*)
echo "Illegal input."
;;
esac
done
return 0
}