mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-12 21:39:48 +01:00
systemadmin: refactor plugin and fix README (#7295)
This commit is contained in:
parent
ecb46c3ec7
commit
0871594f58
2 changed files with 47 additions and 65 deletions
|
@ -10,52 +10,42 @@ plugins=(... systemadmin)
|
||||||
|
|
||||||
## Aliases
|
## Aliases
|
||||||
|
|
||||||
| Alias | Command | Description |
|
| Alias | Command | Description |
|
||||||
|--------|-----------------------------------------------------------------------------------|--------------------------------------------------------------------|
|
|---------|------------------------------------------------------------------------|--------------------------------------------------------------------|
|
||||||
| ping | `ping -c 5` | Sends only 5 ICMP Messages |
|
| ping | `ping -c 5` | Sends only 5 ICMP Messages |
|
||||||
| clr | `clear;echo "Currently logged in on $(tty), as $USER in directory $PWD."` | Clears the screen and prings the current user, TTY, and directory |
|
| clr | `clear; echo Currently logged in on $TTY, as $USER in directory $PWD.` | Clears the screen and prints the current user, TTY, and directory |
|
||||||
| path | `echo -e ${PATH//:/\\n}` | Displays PATH with each entry on a separate line |
|
| path | `print -l $path` | Displays PATH with each entry on a separate line |
|
||||||
| mkdir | `mkdir -pv` | Automatically create parent directories and display verbose output |
|
| mkdir | `mkdir -pv` | Automatically create parent directories and display verbose output |
|
||||||
| psmem | <code>ps -e -orss=,args= \| sort -b -k1,1n</code> | Display the processes using the most memory |
|
| psmem | `ps -e -orss=,args= \| sort -b -k1,1n` | Display the processes using the most memory |
|
||||||
| psmem10| <code>ps -e -orss=,args= \| sort -b -k1,1n\| head -10</code> | Display the top 10 processes using the most memory |
|
| psmem10 | `ps -e -orss=,args= \| sort -b -k1,1n \| head -10` | Display the top 10 processes using the most memory |
|
||||||
| pscpu | <code>ps -e -o pcpu,cpu,nice,state,cputime,args\|sort -k1 -nr</code> | Display the top processes using the most CPU |
|
| pscpu | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr` | Display the top processes using the most CPU |
|
||||||
| pscpu10| <code>ps -e -o pcpu,cpu,nice,state,cputime,args\|sort -k1 -nr \| head -10</code> | Display the top 10 processes using the most CPU |
|
| pscpu10 | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr \| head -10` | Display the top 10 processes using the most CPU |
|
||||||
| hist10 | <code>print -l ${(o)history%% *} \| uniq -c \| sort -nr \| head -n 10</code> | Display the top 10 most used commands in the history |
|
| hist10 | `print -l ${(o)history%% *} \| uniq -c \| sort -nr \| head -n 10` | Display the top 10 most used commands in the history |
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
## Named Functions
|
| Function | Description |
|
||||||
These are used by some of the other functions to provide flexibility
|
|-------------|-----------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| dls | List only directories in the current directory |
|
||||||
| Function | Description |
|
| psgrep | List all processes that match the pattern input after the command |
|
||||||
|-------------|---------------------------------------------------------------------------------------------------------------------------------------|
|
| killit | Kills any process that matches a regular expression passed to it |
|
||||||
| retval | Returns the first argument or a '.' if no arguments are specified |
|
| tree | List contents of directories in a tree-like format (if tree isn't installed) |
|
||||||
| retlog | Returns the first argument or /var/log/nginx/access.log if no arguments are specified |
|
| sortcons | Sort connections by state |
|
||||||
|
| con80 | View all 80 Port Connections |
|
||||||
## Unamed Functions
|
| sortconip | On the connected IP sorted by the number of connections |
|
||||||
These functions are closer to aliases with complex arguments simplified (in most cases) into one line
|
| req20 | List the top 20 requests on port 80 |
|
||||||
|
| http20 | List the top 20 connections to port 80 based on tcpdump data |
|
||||||
| Function | Description |
|
| timewait20 | List the top 20 time_wait connections |
|
||||||
|-------------|---------------------------------------------------------------------------------------------------------------------------------------|
|
| syn20 | List the top 20 SYN connections |
|
||||||
| dls | List only directories in the current directory |
|
| port_pro | Output all processes according to the port number |
|
||||||
| psgrep | List all processes that match the pattern input after the command |
|
| accessip10 | List the top 10 accesses to the ip address in the nginx/access.log file or another log file if specified |
|
||||||
| killit | xargs sudo kill | Kills any process that matches a regulr expression passed to it |
|
| visitpage20 | List the top 20 most visited files or pages in the nginx/access.log file or another log file if specified |
|
||||||
| tree | List contents of directories in a tree-like format (if tree is installed) |
|
| consume100 | List the 100 most time-consuming Page lists (more than 60 seconds) as well as the corresponding number of occurrences |
|
||||||
| sortcons | Sort connections by state |
|
| webtraffic | List website traffic statistics in GB from tne nginx/access.log file or another log file if specified |
|
||||||
| con80 | View all 80 Port Connections |
|
| c404 | List statistics on 404 connections in the nginx/access.log file or another log file if specified |
|
||||||
| sortconip | On the connected IP sorted by the number of connections |
|
| httpstatus | List statistics based on http status in the nginx/access.log file or another log file if specified |
|
||||||
| req20 | List the top 20 requests on port 80 |
|
| d0 | Delete 0 byte files recursively in the current directory or another if specified |
|
||||||
| http20 | List the top 20 connections to port 80 based on tcpdump data |
|
| geteip | Gather information regarding an external IP address using [icanhazip.com](https://icanhazip.com) |
|
||||||
| timewait20 | List the top 20 time_wait connections |
|
| getip | Determine the local IP Address with `ip addr` or `ifconfig` |
|
||||||
| syn20 | List the top 20 SYN connections |
|
| clrz | Clear zombie processes |
|
||||||
| port_pro | Output all processes according to the port number |
|
| conssec | Show number of concurrent connections per second based on ngnix/access.log file or another log file if specified |
|
||||||
| accessip10 | List the top 10 accesses to the ip address in the nginx/access.log file or another log file if specified as an argument |
|
|
||||||
| visitpage20 | List the top 20 most visited files or pages in the nginx/access.log file or another log file if specified as an argument |
|
|
||||||
| consume100 | List the top 100 of Page lists the most time-consuming (more than 60 seconds) as well as the corresponding page number of occurrences |
|
|
||||||
| webtraffic | List website traffic statistics in GB from tne nginx/access.log file or another log file if specified as an argument |
|
|
||||||
| c404 | List statistics on 404 connections in the nginx/access.log file or another log file if specified as an argument |
|
|
||||||
| httpstatus | List statistics based on http status in the nginx/access.log file or another log file if specified as an argument |
|
|
||||||
| d0 | Delete 0 byte files recursively in the directory specified (or current directory if none is specificied) |
|
|
||||||
| geteip | Gather information regarding an external IP address |
|
|
||||||
| getip | Determine the local IP Address with `ip addr` or `ifconfig` |
|
|
||||||
| clrz | Clear zombie processes |
|
|
||||||
| conssec | Display the number of concurrent connections per second in the nginix/access.log file or another log file if specified as an argument |
|
|
||||||
|
|
|
@ -12,14 +12,6 @@
|
||||||
#
|
#
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
function retval() {
|
|
||||||
if [[ -z $1 ]];then
|
|
||||||
echo '.'
|
|
||||||
else
|
|
||||||
echo $1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function retlog() {
|
function retlog() {
|
||||||
if [[ -z $1 ]];then
|
if [[ -z $1 ]];then
|
||||||
echo '/var/log/nginx/access.log'
|
echo '/var/log/nginx/access.log'
|
||||||
|
@ -29,8 +21,8 @@ function retlog() {
|
||||||
}
|
}
|
||||||
|
|
||||||
alias ping='ping -c 5'
|
alias ping='ping -c 5'
|
||||||
alias clr='clear;echo "Currently logged in on $(tty), as $USER in directory $PWD."'
|
alias clr='clear; echo Currently logged in on $TTY, as $USER in directory $PWD.'
|
||||||
alias path='echo -e ${PATH//:/\\n}'
|
alias path='print -l $path'
|
||||||
alias mkdir='mkdir -pv'
|
alias mkdir='mkdir -pv'
|
||||||
# get top process eating memory
|
# get top process eating memory
|
||||||
alias psmem='ps -e -orss=,args= | sort -b -k1,1n'
|
alias psmem='ps -e -orss=,args= | sort -b -k1,1n'
|
||||||
|
@ -43,10 +35,10 @@ alias hist10='print -l ${(o)history%% *} | uniq -c | sort -nr | head -n 10'
|
||||||
|
|
||||||
# directory LS
|
# directory LS
|
||||||
dls () {
|
dls () {
|
||||||
ls -l | grep "^d" | awk '{ print $9 }' | tr -d "/"
|
print -l *(/)
|
||||||
}
|
}
|
||||||
psgrep() {
|
psgrep() {
|
||||||
ps aux | grep "$(retval $1)" | grep -v grep
|
ps aux | grep "${1:-.}" | grep -v grep
|
||||||
}
|
}
|
||||||
# Kills any process that matches a regexp passed to it
|
# Kills any process that matches a regexp passed to it
|
||||||
killit() {
|
killit() {
|
||||||
|
@ -54,10 +46,10 @@ killit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# list contents of directories in a tree-like format
|
# list contents of directories in a tree-like format
|
||||||
if [ -z "\${which tree}" ]; then
|
if ! (( $+commands[tree] )); then
|
||||||
tree () {
|
tree () {
|
||||||
find $@ -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
|
find $@ -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Sort connection state
|
# Sort connection state
|
||||||
|
@ -97,7 +89,7 @@ syn20() {
|
||||||
|
|
||||||
# Printing process according to the port number
|
# Printing process according to the port number
|
||||||
port_pro() {
|
port_pro() {
|
||||||
netstat -ntlp | grep "$(retval $1)" | awk '{print $7}' | cut -d/ -f1
|
netstat -ntlp | grep "${1:-.}" | awk '{print $7}' | cut -d/ -f1
|
||||||
}
|
}
|
||||||
|
|
||||||
# top10 of gain access to the ip address
|
# top10 of gain access to the ip address
|
||||||
|
@ -134,7 +126,7 @@ httpstatus() {
|
||||||
|
|
||||||
# Delete 0 byte file
|
# Delete 0 byte file
|
||||||
d0() {
|
d0() {
|
||||||
find "$(retval $1)" -type f -size 0 -exec rm -rf {} \;
|
find "${1:-.}" -type f -size 0 -exec rm -rf {} \;
|
||||||
}
|
}
|
||||||
|
|
||||||
# gather external ip address
|
# gather external ip address
|
||||||
|
|
Loading…
Reference in a new issue