sh_config.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. # ssh 配置
  2. alias ssh-tianyunperfect='ssh -i ~/.ssh/tianyun.pem root@www.tianyunperfect.cn'
  3. alias ssh-yizhi='ssh -i ~/.ssh/yizhi.pem root@www.yizhigj.com'
  4. # 快捷命令
  5. ## 未分类
  6. alias ll='ls -alh --time-style="+%Y-%m-%d %H:%I:%S"'
  7. #du -sh * 2>/dev/null | sort -hr
  8. alias du-sh='du -sh * 2>/dev/null | sort -hr'
  9. alias sourcevenv='source venv/bin/activate'
  10. alias notify='function _notify() { osascript -e "display notification \"$1\""; }; _notify'
  11. ## k8s
  12. function k8s-getnamespace() {
  13. kubectl config view | grep namespace
  14. }
  15. function k8s-setnamespace() {
  16. k8s-getnamespace
  17. kubectl config set-context --current --namespace="$1"
  18. }
  19. function k8s-getpod() {
  20. k8s-getnamespace
  21. # 如果有参数,则过滤
  22. if [ ! -z "$1" ]; then
  23. kubectl get pods -o wide | grep "$1"
  24. else
  25. kubectl get pods -o wide
  26. fi
  27. }
  28. alias k8s-descpods='kubectl describe pods'
  29. function k8s-getlog() {
  30. k8s-getnamespace
  31. podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
  32. kubectl logs --tail=300 -f "${podName}"
  33. }
  34. alias k8s-delpod='kubectl delete pod ${1} --force'
  35. function k8s-inpod() {
  36. k8s-getnamespace
  37. podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
  38. kubectl exec -it "${podName}" -- /bin/bash
  39. }
  40. alias k8s-getsvc='kubectl get svc'
  41. alias k8s-deldeployment='kubectl delete deployment'
  42. alias k8s-getdeployment='kubectl get deployment'
  43. alias k8s-descdeployment='kubectl describe deployment'
  44. alias k8s-getdeploymentgrep='kubectl get deployment | grep'
  45. alias k8s-getingress='kubectl get ingress'
  46. alias k8s-descingress='kubectl describe ingress'
  47. alias k8s-getingressgrep='kubectl get ingress | grep'
  48. ## docker
  49. alias docker-rm-all-image='docker rmi $(docker images -q)'
  50. alias docker-rm-all-docker='docker rm $(docker ps -a -q)'
  51. alias docker-show-image-prune='docker image ls -f dangling=true'
  52. alias docker-image-prune='docker image prune -a'
  53. alias dkstats='docker stats'
  54. alias dkps='docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"'
  55. alias dkpsa='docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"'
  56. alias dkrm='docker rm -f $1'
  57. alias dkrmi='docker rmi -f $1'
  58. alias dkimage='docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}"'
  59. alias dkip='docker inspect --format="{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" $(docker ps -aq)'
  60. alias dkin='docker exec -it $1 /bin/bash'
  61. alias dklog='docker logs -n 300 -f $1'
  62. alias dkinspect='docker inspect $1'
  63. ## go
  64. alias gobuildwinexe='GOOS=windows GOARCH=amd64 go build -o $1.exe $1.go'
  65. alias gobuildlinuxexe='GOOS=linux GOARCH=amd64 go build -o $1 $1.go'
  66. alias gobuildmacexe='GOOS=darwin GOARCH=amd64 go build -o $1 $1.go'
  67. ## version
  68. alias pythonversion='python --version'
  69. alias javaversion='java -version'
  70. alias nodeversion='node -v'
  71. alias centosversion='cat /etc/os-release'
  72. alias ubuntuversion='cat /etc/lsb-release'
  73. alias goversion='go version'
  74. ## ip查看
  75. alias ipremote='curl cip.cc'
  76. function iplocal() {
  77. # 如果是mac 过滤 en0,如果是linux 过滤 eth0
  78. if [[ "$OSTYPE" == "darwin"* ]]; then
  79. ifconfig en0 | grep inet | grep -v inet6
  80. else
  81. ifconfig eth0 | grep inet | grep -v inet6
  82. fi
  83. }
  84. ## 进程相关
  85. alias psgrep='ps aux | grep -v grep | grep'
  86. alias killport='kill -9 $(lsof -t -i:$1)'
  87. alias ps-mem-top6='ps aux --sort=-%mem | awk '\''{print $2, $11, $4, $6/1024 "MB"}'\'' | head -n 6'
  88. # node
  89. alias npminstall='npm install -g --registry=https://registry.npmmirror.com '
  90. # python
  91. alias pipinstall='pip install $1 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com'
  92. # 文件查找相关
  93. alias findname='find . -name *$1*'
  94. alias grepR='grep -R -C 1 -n $1 .'
  95. # 备份
  96. function tar_back()
  97. {
  98. time=$(date "+%Y-%m-%d_%H_%M_%S")
  99. tar -zcvf "${1}".${time}.tgz "$1"
  100. ll -h ${1}.${time}.tgz
  101. }
  102. pid-cmd-centos(){
  103. sudo ls -l /proc/$1/cwd | awk '{print $11}'
  104. sudo cat /proc/$1/cmdline
  105. echo ''
  106. }
  107. pid-cmd-ubuntu() {
  108. ls -l /proc/"$1"/cwd | awk '{print $11}'
  109. tr '\0' ' ' </proc/"$1"/cmdline; echo ""
  110. }
  111. function echo-arthas-install() {
  112. echo '
  113. # 判断是否存在 ~/arthas-boot.jar,如果不存在则下载
  114. if [ ! -f ~/arthas-boot.jar ]; then
  115. ( cd ~ && curl -O https://arthas.gitee.io/arthas-boot.jar )
  116. fi
  117. # 判断是否在k8s里面
  118. if [[ ! -z "$KUBERNETES_SERVICE_HOST" && ! -z "$KUBERNETES_SERVICE_PORT" ]]; then
  119. echo "Running in Kubernetes environment"
  120. java -jar ~/arthas-boot.jar 1 --options json-format=true
  121. else
  122. echo "Not running in Kubernetes environment"
  123. java -jar ~/arthas-boot.jar --options json-format=true
  124. fi
  125. '
  126. }
  127. alias cparthas='echo-arthas-install | pbcopy'
  128. function curl-form() {
  129. curl -d "$2" "$1"
  130. }
  131. function watch-cpudiskmemory() {
  132. watch -n 1 '
  133. echo "===CPU占用摘要:"
  134. top -bn 1 -i -c | grep Cpu
  135. echo "
  136. ===内存占用摘要:"
  137. free -h
  138. echo "
  139. ===磁盘占用摘要:"
  140. df -h /'
  141. }
  142. #123
  143. function vimrc() {
  144. if [[ "$0" =~ "zsh" ]]
  145. then
  146. vim ~/.zshrc
  147. else
  148. vim ~/.bashrc
  149. fi
  150. }
  151. merge_video_audio() {
  152. if [ "$#" -ne 3 ]; then
  153. echo "错误:参数数量不正确!"
  154. echo "用法:merge_video_audio video.mp4 audio.mp3 output.mp4"
  155. return 1
  156. fi
  157. ffmpeg -i "$1" -i "$2" -c:v copy -c:a copy "$3"
  158. }
  159. rm-all() {
  160. find . -name $1 | xargs -I {} rm -rf {}
  161. }
  162. ### mysql
  163. function echo-mysql-tables() {
  164. echo 'SELECT table_name, table_comment FROM information_schema.tables WHERE table_schema = DATABASE();'
  165. }
  166. function echo-mysql-table-size() {
  167. echo 'select table_name,concat(round(sum(DATA_LENGTH/1024/1024),2),"MB") as data from information_schema.TABLES where table_schema =(SELECT DATABASE()) group by table_name;'
  168. }
  169. function echo-mysql-db-size() {
  170. echo 'select table_schema,concat(round(sum(DATA_LENGTH/1024/1024),2),"MB") as data from information_schema.TABLES where table_schema not in ("information_schema","mysql","performance_schema","sys") group by table_schema;'
  171. }
  172. function echo-npm() {
  173. echo '
  174. npm i webpack # 在module文件中安装
  175. npm i webpack -S # --save 常用,添加到package
  176. npm i webpack -D # --save-dev
  177. npm i webpack -g --registry=https://registry.npmmirror.com # 全局
  178. npm un webpack -g
  179. yarn add react
  180. yarn remove react
  181. yarn global add umi
  182. '
  183. }
  184. concat_params() {
  185. # 获取传入的参数个数
  186. num_params=$#
  187. # 判断参数个数是否大于等于1
  188. if [ $num_params -ge 1 ]; then
  189. # 使用循环遍历参数,并拼接在一起
  190. concat_str="$1"
  191. for ((i=2; i<=$num_params; i++)); do
  192. concat_str+="%20${!i}"
  193. done
  194. # 打印拼接后的字符串
  195. echo "$concat_str"
  196. else
  197. echo "没有传入参数"
  198. fi
  199. }
  200. function url_encode() {
  201. echo "$1" | sed 's/ /%20/g'
  202. }
  203. function bing() {
  204. ## 如果是windows系统,则使用start,否则使用open,后面的参数可以有多个空格
  205. if [[ "$OSTYPE" == "msys"* ]]; then
  206. search_query=$(concat_params "$@")
  207. start "https://www.bing.com/search?q=$search_query"
  208. else
  209. search_query=""
  210. for query in "$@"; do
  211. search_query+=" $query"
  212. done
  213. search_query=$(url_encode "$search_query")
  214. open "https://www.bing.com/search?q=${search_query}"
  215. fi
  216. }