minor fixes, updates

- signed-off-by: trimstray <trimstray@gmail.com>
This commit is contained in:
trimstray 2018-07-12 21:15:08 +02:00
parent f4aaa468dd
commit 0be3ddfa01

View File

@ -389,7 +389,11 @@ some_command > >(/bin/cmd_for_stdout) 2> >(/bin/cmd_for_stderr)
###### List of commands you use most often ###### List of commands you use most often
```bash ```bash
history | awk '{ a[$2]++ } END { for(i in a) { print a[i] " " i } }' | sort -rn | head history | \
awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | \
grep -v "./" | \
column -c3 -s " " -t | \
sort -nr | nl | head -n 20
``` ```
###### Empty a file (truncate to 0 size) ###### Empty a file (truncate to 0 size)
@ -771,7 +775,10 @@ ___
###### Show 20 biggest directories with 'K M G' ###### Show 20 biggest directories with 'K M G'
```bash ```bash
du | sort -r -n | awk '{split("K M G",v); s=1; while($1>1024){$1/=1024; s++} print int($1)" "v[s]"\t"$2}' | head -n 20 du | \
sort -r -n | \
awk '{split("K M G",v); s=1; while($1>1024){$1/=1024; s++} print int($1)" "v[s]"\t"$2}' | \
head -n 20
``` ```
___ ___
@ -1359,8 +1366,8 @@ __EOF__
```bash ```bash
server> while : ; do \ server> while : ; do \
(echo -ne "HTTP/1.1 200 OK\r\nContent-Length: $(wc -c <index.html)\r\n\r\n" ; cat index.html;) \ (echo -ne "HTTP/1.1 200 OK\r\nContent-Length: $(wc -c <index.html)\r\n\r\n" ; cat index.html;) | \
| nc -l -p 5000 \ nc -l -p 5000 \
; done ; done
``` ```
@ -1394,10 +1401,11 @@ mkfifo -m 0600 "$_back" "$_sent" "$_recv"
sed "s/^/=> /" <"$_sent" & sed "s/^/=> /" <"$_sent" &
sed "s/^/<= /" <"$_recv" & sed "s/^/<= /" <"$_recv" &
nc -l -p "$_listen_port" <"$_back" \
| tee "$_sent" \ nc -l -p "$_listen_port" <"$_back" | \
| nc "$_bk_host" "$_bk_port" \ tee "$_sent" | \
| tee "$_recv" >"$_back" nc "$_bk_host" "$_bk_port" | \
tee "$_recv" >"$_back"
``` ```
```bash ```bash
@ -1518,9 +1526,9 @@ lsof -u username -a +D /etc
###### Show 10 Largest Open Files ###### Show 10 Largest Open Files
```bash ```bash
lsof / \ lsof / | \
| awk '{ if($7 > 1048576) print $7/1048576 "MB" " " $9 " " $1 }' \ awk '{ if($7 > 1048576) print $7/1048576 "MB" " " $9 " " $1 }' | \
| sort -n -u | tail | column -t sort -n -u | tail | column -t
``` ```
___ ___
@ -1530,7 +1538,13 @@ ___
###### Graph # of connections for each hosts ###### Graph # of connections for each hosts
```bash ```bash
netstat -an | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | grep -v -e '^[[:space:]]*$' | sort | uniq -c | awk '{ printf("%s\t%s\t",$2,$1) ; for (i = 0; i < $1; i++) {printf("*")}; print "" }' netstat -an | \
grep ESTABLISHED | \
awk '{print $5}' | \
awk -F: '{print $1}' | \
grep -v -e '^[[:space:]]*$' | \
sort | uniq -c | \
awk '{ printf("%s\t%s\t",$2,$1) ; for (i = 0; i < $1; i++) {printf("*")}; print "" }'
``` ```
###### Monitor open connections for specific port including listen, count and sort it per IP ###### Monitor open connections for specific port including listen, count and sort it per IP
@ -1607,15 +1621,15 @@ ___
```bash ```bash
AS="AS32934" AS="AS32934"
whois -h whois.radb.net -- "-i origin ${AS}" \ whois -h whois.radb.net -- "-i origin ${AS}" | \
| grep "^route:" \ grep "^route:" | \
| cut -d ":" -f2 \ cut -d ":" -f2 | \
| sed -e 's/^[ \t]//' \ sed -e 's/^[ \t]//' | \
| sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 \ sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | \
| cut -d ":" -f2 \ cut -d ":" -f2 | \
| sed -e 's/^[ \t]/allow /' \ sed -e 's/^[ \t]/allow /' | \
| sed 's/$/;/' \ sed 's/$/;/' | \
| sed 's/allow */subnet -> /g' sed 's/allow */subnet -> /g'
``` ```
###### Resolves domain name from dns.google.com with curl and jq ###### Resolves domain name from dns.google.com with curl and jq