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