写一个脚本,定一个数组,数组中的元素是/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.178linux.com/39690