shell 注意事项

shell注意事项

  • 记录日志

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

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

  • 备注

#记录日志
#!/bin/bash

shell_log="./shell_log"

#Writelog
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

#shellEnv
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=`catyuming`

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

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

#AllFunction
all(){
fastcdn$1
local$1
echo
}

#shell_lock
shell_lock(){
touch$shell_lock_file
}

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

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

#Exec
main$1

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...