删除apache的签名的shell脚本

删除apache的签名脚本。

    #!/usr/bash
    #modify Apache conf to add ServerSignature Off and ServerTokens Prod to remove Apache server signature

    APACHE_CFG_FILE=/etc/httpd/conf/httpd.conf
    FindServerSignatureOff=`grep "^ServerSignature Off$" $APACHE_CFG_FILE`
    if [[ -z $FindServerSignatureOff ]]; then
        sed  -e 's/^ServerSignature/#&/' -e '$aServerSignature Off' -i $APACHE_CFG_FILE           
        requiresApacheRestart=1
    fi

    FindServerTokensProd=`grep "^ServerTokens Prod$" $APACHE_CFG_FILE`
    if [[ -z $FindServerTokensProd ]]; then
        sed  -e 's/^ServerTokens/#&/' -e '$aServerTokens Prod' -i $APACHE_CFG_FILE          
        requiresApacheRestart=1
    fi

    #Restart apache to pick up changes
    if [ $requiresApacheRestart -eq 1 ]; then
        log "INFO: modifyApacheSecurityConfig() - Restarting apache to activate new values"
        service httpd restart
    fi

注意几点:
1. 判断在文件中是否存在某个字符串用-z/-n, 其中 -z表示grep到的字符串为空,也即不存在,-n表示grep到的字符串不为空,也即存在。判断的时候要用[[ ]], 不是[ ]
2. sed 可以用-e (即表达多),来操作多个表达式,-i表示in-place
3. 最后要重启了httpd deamon service才能生效。
4. 具体请参见:http://blog.csdn.net/qianggezhishen/article/details/46711405

posted @ 2015-07-22 17:19  chenqiangzhishen  阅读(128)  评论(0编辑  收藏  举报