summaryrefslogtreecommitdiff
path: root/plugins/systemadmin
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/systemadmin')
-rw-r--r--plugins/systemadmin/README.md51
-rw-r--r--plugins/systemadmin/systemadmin.plugin.zsh35
2 files changed, 64 insertions, 22 deletions
diff --git a/plugins/systemadmin/README.md b/plugins/systemadmin/README.md
new file mode 100644
index 000000000..edca4d87d
--- /dev/null
+++ b/plugins/systemadmin/README.md
@@ -0,0 +1,51 @@
+# Systemadmin plugin
+
+This plugin adds a series of aliases and functions which make a System Administrator's life easier.
+
+To use it, add `systemadmin` to the plugins array in your zshrc file:
+
+```zsh
+plugins=(... systemadmin)
+```
+
+## Aliases
+
+| Alias | Command | Description |
+|---------|------------------------------------------------------------------------|--------------------------------------------------------------------|
+| 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 prints the current user, TTY, and directory |
+| path | `print -l $path` | Displays PATH with each entry on a separate line |
+| mkdir | `mkdir -pv` | Automatically create parent directories and display verbose output |
+| psmem | `ps -e -orss=,args= \| sort -b -k1,1n` | Display the 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 | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr` | Display the top 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 | `print -l ${(o)history%% *} \| uniq -c \| sort -nr \| head -n 10` | Display the top 10 most used commands in the history |
+
+## Functions
+
+| Function | Description |
+|-------------|-----------------------------------------------------------------------------------------------------------------------|
+| dls | List only directories in the current directory |
+| psgrep | List all processes that match the pattern input after the command |
+| killit | Kills any process that matches a regular expression passed to it |
+| tree | List contents of directories in a tree-like format (if tree isn't installed) |
+| sortcons | Sort connections by state |
+| con80 | View all 80 Port Connections |
+| sortconip | On the connected IP sorted by the number of connections |
+| req20 | List the top 20 requests on port 80 |
+| http20 | List the top 20 connections to port 80 based on tcpdump data |
+| timewait20 | List the top 20 time_wait connections |
+| syn20 | List the top 20 SYN connections |
+| port_pro | Output all processes according to the port number |
+| accessip10 | List the top 10 accesses to the ip address in the nginx/access.log file or another log file if specified |
+| visitpage20 | List the top 20 most visited files or pages in the nginx/access.log file or another log file if specified |
+| consume100 | List the 100 most time-consuming Page lists (more than 60 seconds) as well as the corresponding number of occurrences |
+| webtraffic | List website traffic statistics in GB from tne nginx/access.log file or another log file if specified |
+| c404 | List statistics on 404 connections in the nginx/access.log file or another log file if specified |
+| httpstatus | List statistics based on http status in the nginx/access.log file or another log file if specified |
+| d0 | Delete 0 byte files recursively in the current directory or another if specified |
+| geteip | Gather information regarding an external IP address using [icanhazip.com](https://icanhazip.com) |
+| getip | Determine the local IP Address with `ip addr` or `ifconfig` |
+| clrz | Clear zombie processes |
+| conssec | Show number of concurrent connections per second based on ngnix/access.log file or another log file if specified |
diff --git a/plugins/systemadmin/systemadmin.plugin.zsh b/plugins/systemadmin/systemadmin.plugin.zsh
index 8c2633355..bdc2219fa 100644
--- a/plugins/systemadmin/systemadmin.plugin.zsh
+++ b/plugins/systemadmin/systemadmin.plugin.zsh
@@ -3,7 +3,6 @@
# -----------
#
# This is one for the system administrator, operation and maintenance.
-# Some of which come from http://justinlilly.com/dotfiles/zsh.html
#
# ------------------------------------------------------------------------------
# Authors
@@ -13,14 +12,6 @@
#
# ------------------------------------------------------------------------------
-function retval() {
- if [[ -z $1 ]];then
- echo '.'
- else
- echo $1
- fi
-}
-
function retlog() {
if [[ -z $1 ]];then
echo '/var/log/nginx/access.log'
@@ -30,8 +21,8 @@ function retlog() {
}
alias ping='ping -c 5'
-alias clr='clear;echo "Currently logged in on $(tty), as $USER in directory $PWD."'
-alias path='echo -e ${PATH//:/\\n}'
+alias clr='clear; echo Currently logged in on $TTY, as $USER in directory $PWD.'
+alias path='print -l $path'
alias mkdir='mkdir -pv'
# get top process eating memory
alias psmem='ps -e -orss=,args= | sort -b -k1,1n'
@@ -44,10 +35,10 @@ alias hist10='print -l ${(o)history%% *} | uniq -c | sort -nr | head -n 10'
# directory LS
dls () {
- ls -l | grep "^d" | awk '{ print $9 }' | tr -d "/"
+ print -l *(/)
}
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
killit() {
@@ -55,10 +46,10 @@ killit() {
}
# list contents of directories in a tree-like format
-if [ -z "\${which tree}" ]; then
- tree () {
- find $@ -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
- }
+if ! (( $+commands[tree] )); then
+ tree () {
+ find $@ -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
+ }
fi
# Sort connection state
@@ -98,7 +89,7 @@ syn20() {
# Printing process according to the port number
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
@@ -135,7 +126,7 @@ httpstatus() {
# Delete 0 byte file
d0() {
- find "$(retval $1)" -type f -size 0 -exec rm -rf {} \;
+ find "${1:-.}" -type f -size 0 -exec rm -rf {} \;
}
# gather external ip address
@@ -143,12 +134,12 @@ geteip() {
curl -s -S https://icanhazip.com
}
-# determine local IP address
+# determine local IP address(es)
getip() {
if (( ${+commands[ip]} )); then
- ip addr | grep "inet " | grep -v '127.0.0.1' | awk '{print $2}'
+ ip addr | awk '/inet /{print $2}' | command grep -v 127.0.0.1
else
- ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'
+ ifconfig | awk '/inet /{print $2}' | command grep -v 127.0.0.1
fi
}