- awk使用,取出df中大于50%的文件系统
我编了一个文件如下:
root@wis-virtual-machine:/wis/testdir1# cat df.txt Filesystem Size Used Avail Use% Mounted on udev 482M 0 482M 0% /dev tmpfs 100M 5.5M 95M 70% /run /dev/sda1 19G 8.3G 9.4G 48% / /dev/mapper/vgw_lv_name 19G 8.3G 9.4G 58% /wis
想把大于50%的文件系统输出,了如下代码:
root@wis-virtual-machine:/wis/testdir1# cat df.txt |awk 'BEGIN{limit=50}NR==1{print}NF==1{lvname=$1}NF==6{if($5+0>limit)print}NF==5{if($4+0>limit)print lvname"\n"$0}' Filesystem Size Used Avail Use% Mounted on tmpfs 100M 5.5M 95M 70% /run /dev/mapper/vgw_lv_name 19G 8.3G 9.4G 58% /wis
这里主要是用($5+0)把70%这样的字符串改成整数的。
- telnet自动登录:
(sleep 1;echo username;sleep 1;echo password; sleep 1;echo cmd;sleep 1;)|telnet hostname
3. 两个文件按列合并
paste
4. 主机名取最后一位数字
echo ${HOSTNAME##*-} ansible beijing-114 -m shell -a "/tmp/net.sh \${HOSTNAME##*-} eth0 eth2" -f 100
5. find正则
find /opt/mydata -mtime +3 -type d -regextype sed -regex "/opt/my_data/[0-9]*"
6. keepalived钉钉告警
cat /etc/keepalived/keepalived.conf |tail -5 notify_master "/etc/keepalived/keepalived_notify.sh master" notify_backup "/etc/keepalived/keepalived_notify.sh backup" notify_fault "/etc/keepalived/keepalived_notify.sh fault" notify_stop "/etc/keepalived/keepalived_notify.sh stop" cat /etc/keepalived/keepalived_notify.sh #!/bin/bash curl "https://oapi.dingtalk.com/robot/send?access_token=token" -H "Accept: application/json" -H "Content-Type:application/json" --data @<(cat <<EOF { "msgtype": "text", "text": { "content": "$HOSTNAME:$1" } } EOF )
7. mac sed 替换
sed -i '' -e 's/old/new/g' *
8. 我写的最长的 awk
for file in /ops/*log do cat <<EOF | curl --data-binary @- http://192.168.56.11:9091/metrics/job/firewall/instance/$(echo $file|sed 's@/ops/@@g'|sed 's@.log@@g') $(awk 'BEGIN{print "# TYPE snat_rule gauge";print "# TYPE snat_rule_max gauge";print "# TYPE snat_rule_current gauge"}/snat/{snat_id=$NF}{}{sub(/ports:/,"")} /%/{gsub("id:", "", snat_id);printf "snat_rule{id=\"%s\",protocol=\"%s\"} %s\n",snat_id,$1,$2;gsub("\\(", "", $3);gsub(/[ \t]+$/,"", $3); printf "snat_rule_max{id=\"%s\",protocol=\"%s\"} %s\n",snat_id,$1,$5; printf "snat_rule_current{id=\"%s\",protocol=\"%s\"} %s\n",snat_id,$1,$3}' $file |sed 's@/ops/@@g'|sed 's@.log@@g' |sed 's@%@@g' ) EOF done
9. kubernetes 配置 PS1 使其显示当前集群和命令空间
tail .zshrc
export PS1='%{$fg[magenta]%}%n@%{$fg[magenta]%}%m%{$reset_color%} %{$fg[blue]%}% $cluster:$(grep namespace $KUBECONFIG|cut -d":" -f 2) $PWD~%{$reset_color%}$' alias aliqak8s01="export KUBECONFIG=~/.kube/config && cluster=aliqak8s01" alias tengxunk8s02="export KUBECONFIG=~/.kube/tengxunk8s02 && cluster=tengxunk8s02" alias tengxunk8s01="export KUBECONFIG=~/.kube/tengxunk8s01 && cluster=tengxunk8s01" aliqak8s01
ubuntu PS1
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;31m\]$(grep namespace ${KUBECONFIG:-$HOME/.kube/config}|cut -d":" -f 2) \[\033[01;34m\]:\w\[\033[00m\]\$ '
10. kubernetes 获取各个 node 的 cpu memory
k get node |awk 'NR>1{print $1}' |while read node; do k get node $node -o json |jq -r .metadata.name,.status.allocatable.cpu,.status.allocatable.memory |xargs |awk '{printf ("%-30s %5s %13s\n",$1,$2,$3)}' ; done
11. mac 升级到 13.0 ssh 配置
Host *
StrictHostKeyChecking no
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa