1.取出连接3306端口连接数前10的ip及连接数
netstat -antlp|grep :3306 |awk '{print $4}'|sort |uniq -c|sort -k 1 -r|head -10
#先sort后uniq -c 统计每个ip出现数量,再按第一列逆序排序(sort -k 1第一列)
2.cut 与 awk 区别
cut默认是以制表符分割,awk默认分隔符是空格(当然制表符也是空格组成的啦)
3.打印某个文件的第M ,N行
head -(M+N)filename|tail -(N-M+1)
sed -n 'm,np' filename
sed -n '(m+1)q;m,np' filename
4.删除用户前一定记得先回收用户的权限,防止以后的安全隐患:(查询-->替换)
/usr/local/mysql/bin/mysql -uXXX -p'XXX' -S /data/mysqldata/3306/mysql.sock -s -e "select user,host from mysql.user where user='hhl' and host='%'"|awk '{print "show grants for \""$1"\"@\""$2"\";" }' | /usr/local/mysql/bin/mysql -uXXX -p'XXX' -S /data/mysqldata/3306/mysql.sock -s | sed -e 's/\(WITH\).*$/\1/' -e 's/\(IDENTIFIED\).*$/\1/'|sed -e 's/WITH//' -e 's/IDENTIFIED//' |sed -e 's/\(GRANT\)/REVOKE/' -e 's/\(TO\)/FROM/'
转载于:https://blog.51cto.com/huanghualiang/1359378