shell 注意事项

前端之家收集整理的这篇文章主要介绍了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
原文链接:https://www.f2er.com/bash/391836.html

猜你在找的Bash相关文章