加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell 注意事项

发布时间:2020-12-15 16:38:31 所属栏目:安全 来源:网络整理
导读:shell注意事项 记录日志 shell执行加锁(针对不能同时执行) 加选项(禁止直接执行) 备注 #记录日志#!/bin/bashshell_log="./shell_log"#Writelogshell_log(){shell_info=$1echo"$(date+%Y-%m-%d)T$(date+%H:%M:%S):$shell_info"}shell_log$1 #综合示例#!/b

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"33[31m----------$1--------------33[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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读