__director

随笔分类 -  shell

shell
kubernetes 获取deployment在使用的镜像(不全)
摘要:for i in `kubectl get deployments.apps | awk 'NR>1{print $1}'`;do kubectl get deployment $i -o jsonpath="{.spec.template.spec.containers[0].image}" ; 阅读全文

posted @ 2021-02-22 20:06 __director 阅读(717) 评论(0) 推荐(0)

kubernetes get deployment xxx -o yaml > deployment.yaml
摘要:过滤噪音 for i in `ls $1`;do sed -i '/{}/d' $1\/$i sed -i '/^status:/,$d' $1\/$i sed -i '/managedFields:/,/manager: kube-controller-manager/d' $1\/$i sed 阅读全文

posted @ 2021-02-22 20:02 __director 阅读(145) 评论(0) 推荐(0)

镜像清理
摘要:#!/usr/bin/env bash#Author: 原件#Data: 2020/12/30#Description: 清理无标签的镜像,保留每个镜像最新的5个tag。 docker system prune -f docker images | awk '{print $1}' | awk '{ 阅读全文

posted @ 2021-02-22 20:00 __director 阅读(62) 评论(0) 推荐(0)

AWK 小用--打印奇偶行
摘要:[root@xiaoyuan mnt]# cat file001 1 2 3 4 5 6 7 8 9 10 [root@xiaoyuan mnt]# awk 'i=!i' file001 1 3 5 7 9 [root@xiaoyuan mnt]# awk '!(i=!i)' file001 2 4 阅读全文

posted @ 2020-04-26 21:40 __director 阅读(148) 评论(0) 推荐(0)

行列互换
摘要:[root@xiaoyuan ~]# cat file0081 2 34 5 67 8 9[root@xiaoyuan ~]# awk '{for(i=1;i<=NF;i++)a[i]=a[i]$i" "}END{for(x in a)print a[x]}' file0081 4 7 2 5 8 阅读全文

posted @ 2020-04-25 21:05 __director 阅读(97) 评论(0) 推荐(0)

shell 随机产生字符串或数字
摘要:产生字符串:法一:echo $RANDOM |md5sum |cut -c 1-6 #这里是产生6位,可以有1-32位 法二: cat /proc/sys/kernel/random/uuid |cut -c 1-8 ed9e032c #这里是产生8位,可以有1-36位 产生数字 法一:date + 阅读全文

posted @ 2020-04-25 15:51 __director 阅读(435) 评论(0) 推荐(0)

awk 按多个字符进行切割
摘要:[root@xiaoyuan ~]# ip a s eth0 | grep inet inet 172.31.142.158/20 brd 172.31.143.255 scope global dynamic eth0 inet 192.168.170.133/24 brd 192.168.170 阅读全文

posted @ 2020-04-24 23:54 __director 阅读(988) 评论(0) 推荐(0)

shell 算数运算
摘要:expr: [root@xiaoyuan ~]# expr 2+4 # 需要空格 2+4[root@xiaoyuan ~]# expr 2 + 46[root@xiaoyuan ~]# expr 2 * 4 # *需要转义,不然报错expr: syntax error[root@xiaoyuan ~ 阅读全文

posted @ 2020-04-24 23:43 __director 阅读(81) 评论(0) 推荐(0)

sell 实现100内偶数和
摘要:#法一 seq -s+ 0 2 100 | bc #法二 awk 'BEGIN{for(i=0;i<=100;i++){if(!(i%2))sum+=i};print sum}' #法三 #!/bin/bash #date 2020/4/24 for i in `seq 100`;do if [ ` 阅读全文

posted @ 2020-04-24 23:28 __director 阅读(124) 评论(0) 推荐(0)

sort 实现逐行排序
摘要:加r为逆序 阅读全文

posted @ 2020-04-24 23:13 __director 阅读(119) 评论(0) 推荐(0)

反转字符串
摘要:#!/bin/bash read -p '请输入:' string size=${#string} for ((i=$size-1;i>=0;i--));do printf "${string:$i:1}" done echo '' 阅读全文

posted @ 2020-04-24 23:02 __director 阅读(87) 评论(0) 推荐(0)

导航