码迷,mamicode.com
首页 > 系统相关 > 详细

shell 注意事项

时间:2017-07-26 17:35:02      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:shell

shell注意事项

  • 记录日志

  • shell执行加锁(针对不能同时执行)

  • 加选项(禁止直接执行)

  • 备注

#记录日志
#!/bin/bash

shell_log="./shell_log"

#Write log
shell_log(){
        shell_info=$1
        echo "$(date +%Y-%m-%d)T$(date +%H:%M:%S) : $shell_info"
}

shell_log $1
#综合示例
#!/bin/bash
#Author:duanyifei
#20170703

#shell Env
fastcdn_local_log="./fastcdn_local_log"
fastcdn_log="./fastcdn_log"
local_log="./local_log"
shell_name="duanyifei.search.sh"
shell_lock_file="/tmp/${shell_name}.lock"
domains=`cat yuming`

#fastcdn Function
fastcdn(){
        echo -e "\033[31m ----------$1--------------  \033[0m"
        dnstmk.pl  -u $1 | grep ‘IN‘
        echo
}

#local Function
local(){
        checklocaldns -u $1
        echo
}

#All Function
all(){
        fastcdn $1
        local $1
        echo
}

#shell_lock
shell_lock(){
    touch $shell_lock_file
}

#shell_unlock
shell_unlock(){
    rm -rf $shell_lock_file
}

#main Function
main(){
    if [ -e $shell_lock_file ];then
        echo "duanyifei_search_shell is running" && exit
    fi
    shell_lock
    case $1 in
        fastcdn)
            rm -rf $fastcdn_log
            for domain in $domains
            do
                fastcdn $domain &>> $fastcdn_log
            done
            ;;
        local)
            rm -rf $local_log
            for domain in $domains
            do
                local $domain &>> $local_log
            done
            ;;
        all)
            rm -rf $fastcdn_local_log
            for domain in $domains
            do
                all $domain &>> $fastcdn_local_log
            done
            ;;
        *)
            echo "Usage: fastcdn | local | all"
    esac
    shell_unlock
}

#Exec
main $1


本文出自 “Rookie on the road” 博客,请务必保留此出处http://duanyifei.blog.51cto.com/9618411/1951097

shell 注意事项

标签:shell

原文地址:http://duanyifei.blog.51cto.com/9618411/1951097

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!