]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/systemadmin/systemadmin.plugin.zsh
8e5e0af71e75725542c5c27eefdcdce2632fb2c6
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / systemadmin / systemadmin.plugin.zsh
1 # ------------------------------------------------------------------------------
2 # Description
3 # -----------
4 #
5 # This is one for the system administrator, operation and maintenance.
6 #
7 # ------------------------------------------------------------------------------
8 # Authors
9 # -------
10 #
11 # * Dongweiming <ciici123@gmail.com>
12 #
13 # ------------------------------------------------------------------------------
14
15 function retlog() {
16     if [[ -z $1 ]];then
17         echo '/var/log/nginx/access.log'
18     else
19         echo $1
20     fi
21 }
22
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'
35
36 # directory LS
37 function dls() {
38     print -l *(/)
39 }
40 function psgrep() {
41     ps aux | grep "${1:-.}" | grep -v grep
42 }
43 # Kills any process that matches a regexp passed to it
44 function killit() {
45     ps aux | grep -v "grep" | grep "$@" | awk '{print $2}' | xargs sudo kill
46 }
47
48 # list contents of directories in a tree-like format
49 if ! (( $+commands[tree] )); then
50     function tree() {
51         find $@ -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
52     }
53 fi
54
55 # Sort connection state
56 function sortcons() {
57     netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn
58 }
59
60 # View all 80 Port Connections
61 function con80() {
62     netstat -nat|grep -i ":80"|wc -l
63 }
64
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
68 }
69
70 # top20 of Find the number of requests on 80 port
71 function req20() {
72     netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20
73 }
74
75 # top20 of Using tcpdump port 80 access to view
76 function http20() {
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
78 }
79
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
83 }
84
85 # top20 of Find SYN connection
86 function syn20() {
87     netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr|head -n20
88 }
89
90 # Printing process according to the port number
91 function port_pro() {
92     netstat -ntlp | grep "${1:-.}" | awk '{print $7}' | cut -d/ -f1
93 }
94
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)"
98 }
99
100 # top20 of Most Visited file or page
101 function visitpage20() {
102     awk '{print $11}' "$(retlog)"|sort|uniq -c|sort -nr|head -n 20
103 }
104
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
110 }
111
112 # Website traffic statistics (G)
113 function webtraffic() {
114     awk "{sum+=$10} END {print sum/1024/1024/1024}" "$(retlog)"
115 }
116
117 # Statistical connections 404
118 function c404() {
119     awk '($9 ~/404/)' "$(retlog)" | awk '{print $9,$7}' | sort
120 }
121
122 # Statistical http status.
123 function httpstatus() {
124     awk '{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}' "$(retlog)"
125 }
126
127 # Delete 0 byte file
128 function d0() {
129     find "${1:-.}" -type f -size 0 -exec rm -rf {} \;
130 }
131
132 # gather external ip address
133 function geteip() {
134     curl -s -S -4 https://icanhazip.com
135     curl -s -S -6 https://icanhazip.com
136 }
137
138 # determine local IP address(es)
139 function getip() {
140     if (( ${+commands[ip]} )); then
141         ip addr | awk '/inet /{print $2}' | command grep -v 127.0.0.1
142     else
143         ifconfig | awk '/inet /{print $2}' | command grep -v 127.0.0.1
144     fi
145 }
146
147 # Clear zombie processes
148 function clrz() {
149     ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9
150 }
151
152 # Second concurrent
153 function conssec() {
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
155 }