【文章內(nèi)容簡(jiǎn)介】
/bin/cp supportfiles/ /etc/chmod +x /etc/chkconfig add mysqldchkconfig mysqld on if [ $? eq 0 ]。then make amp。amp。 make install echo e \n\033[32m\033[0m echo e \033[32mThe $M_FILES_DIR Server Install Success !\033[0m else echo e \033[32mThe $M_FILES_DIR Make or Make install ERROR,Please Check...... exit 0 fifiInstall PHP server if [[ $1 eq 3 ]]。then wget c $P_URL/$P_FILES amp。amp。 tar jxvf $P_FILES amp。amp。 cd $P_FILES_DIR amp。amp。./configure prefix=$P_PREFIX withconfigfilepath=$P_PREFIX/etc withmysql=$M_PREFIX withapxs2=$H_PREFIX/bin/apxs if [ $? eq 0 ]。then make ZEND_EXTRA_LIBS=39。liconv39。 amp。amp。 make install echo e \n\033[32m\033[0m echo e \033[32mThe $P_FILES_DIR Server Install Success !\033[0m else echo e \033[32mThe $P_FILES_DIR Make or Make install ERROR,Please Check...... exit 0 fifiif [[ $1 eq 4 ]]。then sed i 39。/DirectoryIndex/s/39。 $H_PREFIX/conf/ $H_PREFIX/bin/apachectl restart echo AddType application/xdphp .php $H_PREFIX/conf/ IP=`ifconfig eth1|grep Bcast|awk 39。{print $2}39。|cut d: f2` echo You can access ://$IP/cat $H_PREFIX/htdocs/ EOF?phpphpinfo()。?EOFFi6. 循環(huán)語(yǔ)句for For 變量 in 字符串do語(yǔ)句1done案例一,打印seq數(shù)字循環(huán) !/bin/sh for i in `seq 15` do echo “NUM is $i” done案例二,求和1100的值!/bin/bashauto sum 1 100j=0for ((i=1。i=100。i++))do j=`expr $i + $j`doneecho $j案例三,找到相關(guān)log,然后批量打包!/bin/sh for i in `find /var/log name “*.log”` do tar –czf $i done案例四,遠(yuǎn)程主機(jī)批量傳輸文件:!/bin/bashauto scp files for clientby authors wugk 2014for i in `seq 100 200`do scp r /tmp/ root@.$i:/data/webapps/Done案例五,遠(yuǎn)程主機(jī)批量執(zhí)行命令:!/bin/bashauto scp files for clientby authors wugk 2014for i in `seq 100 200`do ssh l root .$i ‘ls /tmp’done7. 循環(huán)語(yǔ)句whilewhile 條件語(yǔ)句do語(yǔ)句1done案例一,while條件判斷數(shù)字 !/bin/shi=1。while [[ $i lt 10 ]]。do echo $i。 ((i++))。done。案例二,擴(kuò)展講解linux read命令read p ‘Please Input number:’案例三,while逐行讀取某個(gè)文件!/bin/shwhile read linedo echo $line。done /etc/hosts綜合腳本編寫(xiě):8. Until循環(huán)語(yǔ)句until 條件 doactiondone直到滿(mǎn)足條件,才退出。否則執(zhí)行action。案例一,條件判斷數(shù)字!/bin/sha=10。until [[ $a lt 0 ]]。doecho $a。((a))。done。 9. Case選擇語(yǔ)句case $arg in pattern1) 語(yǔ)句1 。 pattern2) 語(yǔ)句2 。 *) 語(yǔ)句3 。 esac案例一,創(chuàng)建選擇參數(shù)腳本!/bin/shcase $1 in monitor_log) monitor_log 。 archive_log) archive_log 。 * ) echo Usage:{$0 monitor_log | archive_log |help } 。esac10. select選擇語(yǔ)句Select一般用于選擇菜單的創(chuàng)建,可以配合PS3來(lái)做菜單的打印輸出信息。!/bin/shPS3=What you like most of the open source system?select i in CentOS RedHat Ubuntu doecho Your Select System: $iDone11. Shell編程函數(shù)講解shell允許將一組命令集或語(yǔ)句形成一個(gè)可用塊,這些塊稱(chēng)為shell函數(shù),定義函數(shù)的格式:function name (){ mand1 ........}name編寫(xiě)一個(gè)Apache安裝函數(shù):!/bin/bashauto install LAMP by wugk 201411Httpd define path variableH_FILES=H_FILES_DIR=H_URL=H_PREFIX=/usr/local/apache2/function Apache_install(){Install d web server if [[ $1 eq 1 ]]。then wget c $H_URL/$H_FILES amp。amp。 tar jxvf $H_FILES amp。amp。 cd $H_FILES_DIR amp。amp。./configure prefix=$H_PREFIX if [ $? eq 0 ]。then make amp。amp。 make install e