- How to generate a list of commands base on input list.
# echo a b c | xargs -n 1 echo 'this is '
this is a
this is b
this is c
# nova --no-cache list | grep '[|]' | awk '{print $2}' | tail -n +2 | xargs -n1 echo nova delete
nova delete 0dafascd-e7e5-4531-9542-25132338a3fc
nova delete ffasff56-ef5a-42e8-aa96-594d14538def
nova delete ad509afa-0cc8-111b-a681-7c56cc354957
nova delete b9bfafaf-073d-4732-a9c0-2e6720938357
- Testing if you can establish a TCP session
Connection to 92.52.111.222 80 port [tcp/http] succeeded!
- some of the useful CLIs
fold - Filter for folding lines. This breaks the lines to have a maximum of x width column position (or bytes).
column - columnate lists
- How to check TCP / UDP network and socket statistics
netstat -nntulpa &> $file
cat $file | grep tcp | awk ' { print $6 } ' | sort | uniq
cat $file 2 | grep udp
cat $file | grep tcp | awk ' { print $6 } ' | sort | uniq
CLOSE_WAIT
CLOSING
ESTABLISHED
FIN_WAIT1
FIN_WAIT2
LAST_ACK
LISTEN
SYN_RECV
SYN_SENT
TIME_WAIT
cat $file | grep tcp | awk ' { print $6 } ' | sort | uniq | while read STATE; do echo $STATE; grep $STATE $file | wc -l; done
CLOSE_WAIT
2
CLOSING
8
ESTABLISHED
53
FIN_WAIT1
15
FIN_WAIT2
0
LAST_ACK
136
LISTEN
20
SYN_RECV
166
SYN_SENT
0
TIME_WAIT
2
Other useful links: link1, link2, link3
52 MB ./lib/libwireshark.so.2.0.2
17 MB ./lib/x86_64-linux-gnu/libicudata.so.48.1.1
- How to sort files based on file size
52 MB ./lib/libwireshark.so.2.0.2
17 MB ./lib/x86_64-linux-gnu/libicudata.so.48.1.1
- How to cat and highlight a word in text
$echo -n 'ello' | ( read a; read -u1 b ; echo "1st read : - $a -"; echo "2th read : = $b =" ) test 1st read : - ello - 2th read : = test =
- How to truncated and shrink the text output to your terminal screen width
- List Rackspace Openstack cloud servers ip in more readable way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nova list | egrep -v 'ID|-----' | awk -F'|' '{print $2 }' | ( echo 'name pub-new(rc) ip priv-net ip init-net ip' ; while read cs; do nova show $cs | egrep ' name |accessIPv4|public network|private' | awk -F"|" '{for (i=1;i<=NF;i++) gsub (/^ */,"",$i); print $2,$3}' | sort | xargs echo | awk ' { print $4,$1,$2,$5,$6,$7,$8 }'; done ) | column -t | |
name pub-new(rc) ip priv-net ip init-net ip | |
APP01 accessIPv4 1.2.3.141 privatenetwork 10.208.64.184 publicnetwork 1111:1a11:1111:2222:3333:2222:ff08:a1ce,11.13.12.17 | |
APP01 accessIPv4 1.2.3.140 privatenetwork 10.208.97.95 publicnetwork 11.13.140.6,1111:2222:3333:4444:5555:ae11:ff08:70b5 | |
APP02 accessIPv4 1.2.3.238 privatenetwork 10.208.97.115 publicnetwork 11.13.140.46,1111:2222:3333:4444:5555:ae11:ff08:9586 | |
APP03 accessIPv4 1.2.3.142 privatenetwork 10.208.102.109 publicnetwork 11.13.177.167,1111:2222:3333:4444:5555:ae11:ff08:1300 |
$ cat tmp1 a1 a2 a3 a4
Remove the fist line
$ cat tmp1 | tail -n+2 a2 a3 a4
Remove the line #2 and #3
cat tmp1 | sed '2,3d' a1 a4
Remove the first 2 lines
$ cat tmp1 | tail -n+3 a3 a4
- How to extract IP address from tcpdump output
$ tcpdump -nr attack.log 21:35:49.553423 IP 162.13.0.27.22 > 82.44.149.5.51227: Flags [P.], seq 567291273:567291325, ack 2916928547, win 312, length 52 21:35:49.573227 IP 82.44.149.5.51227 > 162.13.0.27.22: Flags [.], ack 52, win 16516, length 0
Extract source IP and port
$ tcpdump -nr attack.log | tmp.xt |awk '{print $3}' 162.13.0.27.22 82.44.149.5.51227
Strip of the port number
$ tcpdump -nr attack.log | awk '{print $3}' | grep -oE '[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}' 162.13.0.27 82.44.149.5
- How to count strings in a text using awk
$ cat | awk ' { count+=NF } END { print count;}' 1 2 aaaa :rrr :ddjf -dd rrd ccc zz 1 2 3 4 444; -d df 16
No comments:
Post a Comment