寫一個腳本,定一個數組,數組中的元素是/var/log目錄下所有以.log結尾的文件,要統計其下標為偶數的文件中的行數之和
[root@localhost sh.log]# cat declaresum.sh #!/bin/bash #author:DYW #寫一個腳本,定一個數組,數組中的元素是/var/log目錄下所有以.log結尾的文件,要統計其下標為偶數的文件中的行數之和 declare -a file file=(/var/log/*.log) declare -i h=0 for i in $(seq 0 $[${#file[*]}-1]); do if [ $[$i%2] -eq 0 ];then let h+=$(wc -l ${file[$i]} | cut -d' ' -f1) fi done echo "Line: $h" [root@localhost sh.log]# bash declaresum.sh Line: 273
生成10個隨機數,采用冒泡算法進行升序或降序排序
[root@localhost sh.log]# cat random.txt 13913 16102 7027 18130 9241 6103 19511 28631 22837 22430 [root@localhost sh.log]# cat maopao.sh #!/bin/bash #author:DYW #生成10個隨機數,采用冒泡的算法進行升序或降序排序 NUM_FILE=./random.txt #get number from file ######################################################### swap_element(){ local tmp=0 tmp=${NUM_SEQUENCE[$1]} NUM_SEQUENCE[$1]=${NUM_SEQUENCE[$2]} NUM_SEQUENCE[$2]=$tmp } show_element(){ echo "${NUM_SEQUENCE[*]},swap $swap_count times" } ######################################################### # #The original bubble sort. bubble_sort_orgi(){ for ((i=0;i<${#NUM_SEQUENCE[*]}-1;i++)) do for ((j=0;j<${#NUM_SEQUENCE[@]}-i-1;j++)) do if [ ${NUM_SEQUENCE[$j]} $1 ${NUM_SEQUENCE[$[j+1]]} ] then swap_element $j $[j+1] let swap_count++ fi done done } #Use the original bubble sort,by increase NUM_SEQUENCE=(`cat $NUM_FILE`) bubble_sort_orgi -gt show_element #Use the original bubble sort,by decrease NUM_SEQUENCE=(`cat $NUM_FILE`) swap_count=0 bubble_sort_orgi -lt show_element # #With a flag to mark the sequence,if the sequence has been order,stop bubble_sort_flag(){ flag=0 for ((i=0;i<${#NUM_SEQUENCE[@]}-1,!flag;i++)) do flag=1 for ((j=0;j<${#NUM_SEQUENCE[*]}-i-1;j++)) do if [ ${NUM_SEQUENCE[$j]} $1 ${NUM_SEQUENCE[$[j+1]]} ] then swap_element $j $[j+1] flag=0 let swap_count++ fi done done } #bubble with flag. NUM_SEQUENCE=(`cat $NUM_FILE`) swap_count=0 bubble_sort_flag -gt show_element # NUM_SEQUENCE=(`cat $NUM_FILE`) swap_count=0 bubble_sort_flag -lt show_element # #Record the last position of bubble sort bubble_sort_last(){ current=0 last=$[${#NUM_SEQUENCE[*]}-1] while [ $last -gt 0 ] do for ((i=current=0;i<last;i++)) do if [ ${NUM_SEQUENCE[$i]} $1 ${NUM_SEQUENCE[$[i+1]]} ] then swap_element $i $[i+1] current=$i let swap_count++ fi done last=$current done } # #Record last order position. NUM_SEQUENCE=(`cat $NUM_FILE`) swap_count=0 bubble_sort_last -gt show_element # NUM_SEQUENCE=(`cat $NUM_FILE`) swap_count=0 bubble_sort_last -lt show_element # #Bidirectional bubble sort bubble_sort_bid(){ head=0 tail=$[${#NUM_SEQUENCE[*]}-1] while [ $head -lt $tail ] do for ((i=head;i<tail;i++)) do if [ ${NUM_SEQUENCE[$i]} $1 ${NUM_SEQUENCE[$[i+1]]} ] then swap_element $i $[i+1] index=$i let swap_count++ fi done tail=$index for ((i=tail;i>head;i--)) do if [ ! ${NUM_SEQUENCE[$i]} $1 ${NUM_SEQUENCE[$[i-1]]} ] then swap_element $i $[i-1] index=$i let swap_count++ fi done head=$index done } # #increase NUM_SEQUENCE=(`cat $NUM_FILE`) swap_count=0 bubble_sort_bid -gt show_element # #decrease NUM_SEQUENCE=(`cat $NUM_FILE`) swap_count=0 bubble_sort_bid -lt show_element # unset i j index head tail NUM_FILE NUM_SEQUENCE swap_count last tmp flag [root@localhost sh.log]# bash maopao.sh 6103 7027 9241 13913 16102 18130 19511 22430 22837 28631,swap 13 times 28631 22837 22430 19511 18130 16102 13913 9241 7027 6103,swap 32 times 6103 7027 9241 13913 16102 18130 19511 22430 22837 28631,swap 13 times 28631 22837 22430 19511 18130 16102 13913 9241 7027 6103,swap 32 times 6103 7027 9241 13913 16102 18130 19511 22430 22837 28631,swap 13 times 28631 22837 22430 19511 18130 16102 13913 9241 7027 6103,swap 32 times 6103 7027 9241 13913 16102 18130 19511 22430 22837 28631,swap 13 times 28631 22837 22430 19511 18130 16102 13913 9241 7027 6103,swap 32 times
刪除rpm包如何恢復
1.刪除rpm包
2.重啟選擇光盤引導,Rescue救援模式。
3.此時硬盤的/是/mnt/sysimage,所以安裝時要指向/是/mnt/sysimage
源碼安裝apache
1.首先下載一個apache的包,解壓。
解壓后會生成一個目錄
2.目錄里有configure,執行生成makefile
–prefix指定安裝在哪個目錄下,默認在/usr/local/apache2下,
–sysconfdir指定配置文件放在哪個目錄下。默認在prefix指定目錄下/etc下
3.make
4.make install 創建
5.安裝后的配置
1)二進制程序目錄導入至PATH環境變量中
文件方式實現
[root@localhost http2.2.29]# vim /etc/profile.d/http2.2.29 PATH=$PATH:/usr/local/http2.2.29/bin [root@localhost http2.2.29]# . /etc/profile.d/http2.2.29 [root@localhost http2.2.29]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/http2.2.29/bin
2)導入庫文件
鏈接方式實現
[root@localhost ld.so.conf.d]# vim /etc/ld.so.conf.d/http2.2.29.conf /usr/local/http2.2.29/lib [root@localhost ld.so.conf.d]# ldcofig -v
3)導入頭文件
[root@localhost ld.so.conf.d]# ln -sv /usr/local/http2.2.29/include/ /usr/include/http2.2.29 ‘/usr/include/http2.2.29’ -> ‘/usr/local/http2.2.29/include/’
4)導入幫助文檔
[root@localhost ld.so.conf.d]# vim /etc/man_db.conf MANDATORY_MANPATH /usr/local/http2.2.29/man [root@localhost ld.so.conf.d]# . /etc/man_db.conf
6.啟動服務
apachetc start
原創文章,作者:DYW,如若轉載,請注明出處:http://www.www58058.com/39690