zoukankan      html  css  js  c++  java
  • 五年屌丝运维工作shell精华

    屌丝运维常用shell
    列出你最常用的10条shell
    history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
    history | awk '{a[$4]++}END{for(i in a){print a[$i] " " i}}' | sort -rn | head
    grep -v "#" .bash_history |awk '{++a[$1]}END{for(i in a)print i,a[i]|"sort -k2 -nr"}'  | head
    网络连接数目
    netstat -an | grep -E "^(tcp)" | cut -c 68- | sort | uniq -c | sort -n     #查看状态数连接数
    netstat -ntu | awk '{print $5" "}' | cut -d: -f1 | sort | uniq -c | sort -nr|head -n 20 #统计IP连接数
    netstat -an -t | grep ":22" | grep ESTABLISHED | awk '{printf "%s %s ",$5,$6}' | sort | wc -l #进程连接数
    取网卡IP
    /sbin/ifconfig |sed 's/.*inet addr:(.*) Bca.*/1/g' |sed -n '/br/{n;p}' #双网卡绑定用这个
    /sbin/ifconfig |sed 's/.*inet addr:(.*) Bca.*/1/g' |sed -n '/eth/{n;p}' #普通网卡用这个
    ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6-  或者
    ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'
    系统信息统计
    dmidecode -t system |grep -E 'Serial'|awk -F':' '{print $2}' (系统序列号查询)
    cat /proc/cpuinfo  | grep CPU | awk  -F: '{print $2}' |  sort|uniq -c (cpu核数)
    dmidecode -t system |grep 'Product'|awk '{print $3$4}'  (单板设备类型)
    dmidecode | grep -P -A 5 'Memory Device' | grep Size | grep -v Range|grep -i -v "no module"|sed -r 's/^s+//g' | sort|uniq -c (内存大小)
    echo `/sbin/ifconfig |sed 's/.*inet addr:(.*) Bca.*/1/g' |sed -n '/eth/{n;p}' ` `hostname` >>/etc/hosts 取IP和主机名定向到/etc/hostname  
    系统抓包分析
    tcpdump -c 10000 -i eth0 -n dst port 80 > /root/pkts  (tcpdump 抓包 ,用来防止80端口被人攻击时可以分析数据 )
    less | awk ' {printf $3" "}' | cut -d. -f 1-4 | sort | uniq -c | awk '{printf $1" "$2" "}' | sort -n -t   +0 (然后检查IP的重复数 并从小到大排序 注意 "-t +0" 中间是两个空格 )
    系统进程管理
    ps -eo pid,lstart,etime | grep 26871 (进程运行时间)
    lsof -p 10412 (查看进程打开的文件 10412是进程的PID)
    ps -e -o "%C : %p : %z : %a"|sort -k5 -nr  (查看进程 按内存从大到小排列 )
     ps -e -o "%C : %p : %z : %a"|sort -nr     (按cpu利用率从大到小排列)
    ps aux |grep mysql |grep -v grep |awk '{print $2}' |xargs kill -9  (杀掉mysql进程)
    killall -TERM mysqld  杀掉mysql进程:
    ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9 杀掉僵死进程
    网卡流量
    dstat -acdgilmnprstTfy (centos查看网卡流量)
    iftop   (suse系统网卡流量)
    sar -n DEV 1 10 (suse系统网卡流量)
    iotop -o (查看那个进程最磨磁盘)
    文件管理
    删除0字节文件
    find -type f -size 0 -exec rm -rf {} ;
    查看目录下10个大文件
    du -cks * | sort -rn | head -n 10
    du -h --max-depth=1  /home
    用三种方法将两列合并成一行
    cat test
    192.168.110.171
    00:1F:D0:D4:DD:47
    xargs -n 2 < test
    sed 'N;s/ / /' test
    awk -v ORS="" '{printf $0" "}NR%2==0{print " "}' 1 test
    192.168.110.171 00:1F:D0:D4:DD:47

    本文出自 “” 博客,请务必保留此出处http://2364821.blog.51cto.com/2354821/1434094

  • 相关阅读:
    leetcode — spiral-matrix-ii
    leetcode — spiral-matrix
    leetcode — maximum-subarray
    leetcode — n-queens
    leetcode — powx-n
    leetcode — anagrams
    bzoj 2194: 快速傅立叶之二 FFT
    bzoj 4503 两个串 快速傅里叶变换FFT
    Codeforces 762D Maximum path 动态规划
    Codeforces 762C Two strings 字符串
  • 原文地址:https://www.cnblogs.com/wajika/p/6374167.html
Copyright © 2011-2022 走看看