當前位置:首頁 » 存儲配置 » 腳本合並存儲

腳本合並存儲

發布時間: 2023-06-04 19:01:05

Ⅰ 怎麼合並腳本

#!/bin/bash
# ====================================== #
# messaging debug by onlyone33 & ilove3d #
# please keep the author information #
# ====================================== #

debug_msg()
{
export TZ=GMT-8

sleep 2s

am_ret=0
#p=0
until [ $am_ret -eq 1 ]
do
if ps -e | grep am > /dev/null 2>&1
then
am_ret=1
else
sleep 1s
#p=$((p+1))
fi
if [ -f /mmc/mmca1/autorun/ezx_flexbit.cfg ]
then
mount --bind /mmc/mmca1/autorun/ezx_flexbit.cfg /usr/setup/ezx_flexbit.cfg
fi

if [ -f /mmc/mmca1/autorun/ezx_flexbit.cfg ]
then
mount --bind /mmc/mmca1/autorun/ezx_flexbit.cfg /ezx_user/download/appwrite/setup/ezx_flexbit.cfg

done

sleep 10s
misc_ret=`ps -e | grep misc1 | busybox wc -l` > /dev/null 2>&1
#q=0
until [ $misc_ret -eq 4 ]
do
sleep 1s
misc_ret=`ps -e | grep misc1 | busybox wc -l` > /dev/null 2>&1
#q=$((q+1))
done

if ps -e | grep messaging > /dev/null 2>&1
then
#echo am_count=$((p+2)) misc1_count=$((q+10)) >> /ezxlocal/debug_msg_log.txt
#echo messaging fine at `date` >> /ezxlocal/debug_msg_log.txt
exit 0
fi

/usr/SYSqtapp/messaging/messaging &
sleep 2s
fuser -k /usr/SYSqtapp/messaging/messaging
#echo am_count=$((p+2)) misc1_count=$((q+10)) >> /ezxlocal/debug_msg_log.txt
#echo messaging debug at `date` >> /ezxlocal/debug_msg_log.txt
}
debug_msg & (if裡面的東西是可以並列的 )

Ⅱ shell 如何合並多個文件

需求描述
現有多個具有相同命名格式及內容格式的文件,要求編寫shell腳本將它們合並到一個文件中。
被合並文件的命名格式為:YYYYMMDDHHMISS.r,例如:20161018030205.r;文件中包含了若干行記錄,每行記錄包含26個字元,其中第一個字元為標識位,第7到12個字元為時間(格式:YYMMDD),例如:000000161019002925000003N0,該記錄的第一個字元0為標識位,第7到12個字元161019表示時間,即16年的10月19日;合並之後的文件的命名格式為:YYYYMMDD.txt,例如:20161018.txt。
對於合並操作,具體要求為:
1)當天只合並前一天的文件,如今天(10月20日)只合並昨天(10月19日)的文件,文件時間通過文件命名即可看出。
2)標識位為0的記錄會被寫到合並之後的文件中,其他記錄將被過濾掉。
3)時間(即第7到12個字元的值)為前一天的記錄會被寫到合並之後的文件中,其他記錄將被過濾掉。
shell腳本
#!/bin/bash

srcparh=/home/zhou/src
exportpath=/home/zhou/export
linenum=0

return_fail()
{
exit 1
}

function check_config_dir
{
if [ ! -d ${srcparh} ];then
echo "[error]:${srcparh} has not existed!!"
return_fail
fi

if [ ! -d ${exportpath}]; then
echo "[error]:${exportpath} has not existed!!"
return_fail
fi
}

function merge_file
{
##YESTERDAY DATE YYMMDD
YES_DATE_YY=`date -dyesterday +%y%m%d`

##YESTERDAY filename
YES_FILENAME=`date -dyesterday +%Y%m%d`.txt

ONE_DAY_AGO=`date -dyesterday +%y%m%d`

echo"YESTERDAY:${ONE_DAY_AGO}"

echo "`date+%Y-%m-%d` `date +%T`----begin to merge file"

if [ -s ${YES_FILENAME}]; then
echo "warn:yesterday file ${YES_FILENAME} has existed!! now backup it to${YES_FILENAME}_bak."
mv ${YES_FILENAME}${YES_FILENAME}_bak
fi

cd ${srcparh}

file_list_temp=`ls | grep-E "${ONE_DAY_AGO}"`
file_list_count=`ls |grep -E "${ONE_DAY_AGO}" | wc -l`

echo " "
echo "there are${file_list_count} yesterday file(s) to be merged."
echo " "

>${exportpath}/${YES_FILENAME}

for file_name in$file_list_temp
do
echo "now to merge ${file_name}"
cat ${file_name} | grep "^0" >${file_name}_filter_firstline

while read line
do
echo ""
echo "nowto deal this line: ${line}"
echo ""

start_data=+${line:6:6}+

echo"${start_data}" | grep "+${ONE_DAY_AGO}+"
if [ $? -eq 0 ]
then
echo"${line}" >> ${exportpath}/${YES_FILENAME}
linenum=$[linenum+1]
fi
done <${file_name}_filter_firstline

rm*_filter_firstline
done

if [ ${linenum} -gt 0 ]
then
echo "Totally ${linenum} lines havemerged."
fi

if [ ! -s${exportpath}/${YES_FILENAME} ]
then
echo "warn:there is no yesterday file record!!,${exportpath}/${YES_FILENAME} isblank!"
echo " ">${exportpath}/${YES_FILENAME}
fi
}

main()
{
echo " "

echo "this mergetool begins running --------------------"

check_config_dir;

merge_file;

echo"-------------end ---------------------"
}

## Execute main function
main $*576576

腳本說明
第一,在腳本的第3到5行,定義了三個變數,其中srcparh用於存放被合並的文件,exportpath用於存放合並之後的文件,linenum用於表示本次寫到合並之後的文件中的記錄的條數。
第二,return_fail用於在執行出現異常(如srcparh或exportpath所表示的路徑不存在)時退出程序而不進行後續處理。
第三,check_config_dir函數用於檢查srcparh或exportpath所表示的路徑是否存在,如不存在,則不進行後續處理。
第四,merge_file函數是本腳本的核心,它的主要功能是找出srcparh下滿足時間條件的文件,並按照需求要求將文件中的記錄篩選出來,放到結果文件中。如果有滿足條件的記錄,那麼腳本會顯示寫入到結果文件中的記錄的條數。
第五,main函數是整個程序的入口(就像C語言中的main函數一樣),它調用了check_config_dir和merge_file函數。
腳本執行結果
第一,當srcparh所表示的路徑不存在時,執行結果如下:
> ./file_merge_tool.sh

this merge tool begins running --------------------
[error]: /home/zhou/src has not existed!!12341234

第二,當exportpath所表示的路徑不存在時,執行結果如下:
> ./file_merge_tool.sh

this merge tool begins running --------------------
[error]: /home/zhou/export has not existed!!12341234

第三,當srcparh所表示的路徑存在但不包含任何文件時,執行結果如下:
> ./file_merge_tool.sh

this merge tool begins running --------------------
YESTERDAY:161019
2016-10-20 16:30:06----begin to merge file

there are 0 yesterday file(s) to be merged.

warn: there is no yesterday filerecord!!,/home/zhou/export/20161019.txt is blank!
-------------end ---------------------1234567891012345678910

第四,現有四個文件20161018030205.r、20161019030254.r、20161019182531.r、20161019213456.r,每個文件的內容如下:
20161018030205.r文件:
000000161019002925000003N0
000000161019002931000003N0
300000161018002931000003N0
000000161019002926000009Y0
000000161019003150000003N0
20161019030254.r文件:
000000161019004925000003N0
000000161019006931000003N0
100000161019006971000004N0
000000161019007926000009Y0
200000161019006871000004N0
000000161019008150000003N0
20161019182531.r文件:
000000161019001925000003N0
000000161019004931000003N0
000000161018007926000009Y0
000000161019007926000009Y0
000000161019009150000003N0
000000161017007926000009Y0
600000161019007426000009Y0
20161019213456.r文件:
000000161019002925000003N0
000000161019002931000003N0
000000161019002926000009Y0
800000161019002961000003N0
000000161019003150000003N0
將它們上傳到srcparh目錄下,運行腳本,結果如下:
> ./file_merge_tool.sh

this merge tool begins running --------------------
YESTERDAY:161019
2016-10-20 17:08:24----begin to merge file

there are 3 yesterday file(s) to be merged.

now to merge 20161019030254.r

now to deal this line: 000000161019004925000003N0

+161019+

now to deal this line: 000000161019006931000003N0

+161019+

now to deal this line: 000000161019007926000009Y0

+161019+

now to deal this line: 000000161019008150000003N0

+161019+
now to merge 20161019182531.r

now to deal this line: 000000161019001925000003N0

+161019+

now to deal this line: 000000161019004931000003N0

+161019+

now to deal this line: 000000161018007926000009Y0

now to deal this line: 000000161019007926000009Y0

+161019+

now to deal this line: 000000161019009150000003N0

+161019+

now to deal this line: 000000161017007926000009Y0

now to merge 20161019213456.r

now to deal this line: 000000161019002925000003N0

+161019+

now to deal this line: 000000161019002931000003N0

+161019+

now to deal this line: 000000161019002926000009Y0

+161019+

now to deal this line: 000000161019003150000003N0

+161019+
Totally 12 lines have merged.
-------------end ---------------------

對照被合並的文件和結果文件,一共有4個文件,但只有3個文件(20161019030254.r、20161019182531.r、20161019213456.r)滿足時間條件,這3個文件中滿足過濾條件(標識位為0、時間為前一天)的記錄條數為12條,和腳本執行結果一致。
大家也可對本腳本進行更多的測試。
總結
shell腳本在基於Linux的開發中有極為廣泛的應用,因為它靠近底層,執行效率高、部署方便。本文中的腳本也可以作為定時任務部署到機器上,讓它在每天的同一個時間里自動執行。

Ⅲ 按鍵精靈如何合並兩個腳本

製作小精靈的時候,選擇兩個腳本,兩個腳本啟動熱鍵設置不一樣。在一個腳本完成以後,設置按下另一個腳本的啟動熱鍵,這樣另一個就可以運行了。

Ⅳ Jmeter如何把多個人寫的腳本合並到一起

可以使用功能文件->合並,如圖

Ⅳ bat腳本批量合並文本文件(各文件內容用【子文件路徑\原文件名 】隔開),求大神

@echooff
for/f"delims="%%ain('dir/a-d/s/b*.txt')do(
(echo【%%~a】
type"%%~a"
echo,)>>new.temp)
rennew.tempnew.txt
pause


是這個效果嗎?

熱點內容
開源庫編譯管理員 發布:2025-02-06 09:39:14 瀏覽:914
臉書怎麼注冊安卓 發布:2025-02-06 09:36:47 瀏覽:381
車用安卓導航無線打不開什麼原因 發布:2025-02-06 09:27:50 瀏覽:790
安卓與蘋果如何互相傳送文件 發布:2025-02-06 09:27:40 瀏覽:26
華為伺服器盤符如何分配 發布:2025-02-06 09:26:41 瀏覽:560
傳奇h5源碼下載 發布:2025-02-06 09:26:06 瀏覽:78
編譯uclibc 發布:2025-02-06 09:09:04 瀏覽:152
用gcc編譯16位匯編 發布:2025-02-06 09:06:07 瀏覽:823
什麼低端安卓手機不卡 發布:2025-02-06 09:03:32 瀏覽:14
我的世界伺服器卡領地 發布:2025-02-06 08:50:45 瀏覽:256