记录日志
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
原文:http://duanyifei.blog.51cto.com/9618411/1951097