1 # ------------------------------------------------------------------------------
5 # This is one for the system administrator, operation and maintenance.
7 # ------------------------------------------------------------------------------
11 # * Dongweiming <ciici123@gmail.com>
13 # ------------------------------------------------------------------------------
17 echo '/var/log/nginx/access.log'
23 alias ping='ping -c 5'
24 alias clr='clear; echo Currently logged in on $TTY, as $USERNAME in directory $PWD.'
25 alias path='print -l $path'
26 alias mkdir='mkdir -pv'
27 # get top process eating memory
28 alias psmem='ps -e -orss=,args= | sort -b -k1 -nr'
29 alias psmem10='ps -e -orss=,args= | sort -b -k1 -nr | head -n 10'
30 # get top process eating cpu if not work try execute : export LC_ALL='C'
31 alias pscpu='ps -e -o pcpu,cpu,nice,state,cputime,args|sort -k1,1n -nr'
32 alias pscpu10='ps -e -o pcpu,cpu,nice,state,cputime,args|sort -k1,1n -nr | head -n 10'
33 # top10 of the history
34 alias hist10='print -l ${(o)history%% *} | uniq -c | sort -nr | head -n 10'
41 ps aux | grep "${1:-.}" | grep -v grep
43 # Kills any process that matches a regexp passed to it
45 ps aux | grep -v "grep" | grep "$@" | awk '{print $2}' | xargs sudo kill
48 # list contents of directories in a tree-like format
49 if ! (( $+commands[tree] )); then
51 find $@ -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
55 # Sort connection state
57 netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn
60 # View all 80 Port Connections
62 netstat -nat|grep -i ":80"|wc -l
65 # On the connected IP sorted by the number of connections
66 function sortconip() {
67 netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
70 # top20 of Find the number of requests on 80 port
72 netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20
75 # top20 of Using tcpdump port 80 access to view
77 sudo tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -n 20
80 # top20 of Find time_wait connection
81 function timewait20() {
82 netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20
85 # top20 of Find SYN connection
87 netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr|head -n20
90 # Printing process according to the port number
92 netstat -ntlp | grep "${1:-.}" | awk '{print $7}' | cut -d/ -f1
95 # top10 of gain access to the ip address
96 function accessip10() {
97 awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}' "$(retlog)"
100 # top20 of Most Visited file or page
101 function visitpage20() {
102 awk '{print $11}' "$(retlog)"|sort|uniq -c|sort -nr|head -n 20
105 # top100 of Page lists the most time-consuming (more than 60 seconds) as well as the corresponding page number of occurrences
106 function consume100() {
107 awk '($NF > 60 && $7~/\.php/){print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -n 100
108 # if django website or other website make by no suffix language
109 # awk '{print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -n 100
112 # Website traffic statistics (G)
113 function webtraffic() {
114 awk "{sum+=$10} END {print sum/1024/1024/1024}" "$(retlog)"
117 # Statistical connections 404
119 awk '($9 ~/404/)' "$(retlog)" | awk '{print $9,$7}' | sort
122 # Statistical http status.
123 function httpstatus() {
124 awk '{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}' "$(retlog)"
129 find "${1:-.}" -type f -size 0 -exec rm -rf {} \;
132 # gather external ip address
134 curl -s -S -4 https://icanhazip.com
135 curl -s -S -6 https://icanhazip.com
138 # determine local IP address(es)
140 if (( ${+commands[ip]} )); then
141 ip addr | awk '/inet /{print $2}' | command grep -v 127.0.0.1
143 ifconfig | awk '/inet /{print $2}' | command grep -v 127.0.0.1
147 # Clear zombie processes
149 ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9
154 awk '{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}' "$(retlog)"|sort -k 2 -nr|head -n10