Tikejhya: Ashish Nepal

Knowledgebase

Month: July 2017

sed replace epoc to timestamp

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

e.g files:
-rw-r--r-- 1 root root 500000684 Jul 22 08:21 my_log.log.01_1500707421_500000684

ls -lrt *.log* | sed 's/^/echo "/; s/\([0-9]\{10\}\)/`date -d @\1`/; s/$/"/;'

echo "-rw-r--r-- 1 root root 500000684 Jul 22 08:21 my_log.log.01_`date -d @1500707421`_500000684"

s/\([0-9]\{10\}\)/`date -d @\1`/

\1 brings your reference from LHS to RHS

in this case; you could run eval for instance ..

eval $(ls -lrt *.log* | sed 's/^/echo "/; s/\([0-9]\{10\}\)/`date -d @\1`/; s/$/"/;') | sed 's/echo/\n/g'

vi advance commands

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

d0 delete from the beginning till the cursor

>> Indent line by shiftwidth spaces
<< De-indent line by shiftwidth spaces
5>> Indent 5 lines
5== Re-indent 5 lines

>% Increase indent of a braced or bracketed block (place cursor on brace first)
=% Reindent a braced or bracketed block (cursor on brace)
<% Decrease indent of a braced or bracketed block (cursor on brace)
]p Paste text, aligning indentation with surroundings

=i{ Re-indent the 'inner block', i.e. the contents of the block
=a{ Re-indent 'a block', i.e. block and containing braces
=2a{ Re-indent '2 blocks', i.e. this block and containing block

>i{ Increase inner block indent
Decrease inner block indent

lvm howto’s

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

#How to create lvm

pvcreate /dev/xvdb
vgcreate vg_name /dev/xvdb
lvcreate -l 100%FREE -n lg vg
echo , | sfdisk /dev/mapper/vg_name-lg_name
mkfs.ext4 -F /dev/mapper/vg_name-lg_name

#How to extend existing lvm disk space.
Lets assume we have added new disk to EC2 instance

pvcreate /dev/xvdc

Add the physical volume to the volume group via ‘vgextend’.

vgextend vg_name /dev/xvdc
e.g: vgextend disk2 /dev/xvdc

Allocate the physical volume to a logical volume (extend the volume size by your new disk size).

$ lvextend -l +100%FREE /dev/mapper/disk2-esdata

Resize the file system on the logical volume so it uses the additional space.

$ resize2fs /dev/mapper/disk2-esdata

awk all but last

awk 'BEGIN{FS=OFS="_"}{NF--; print}')

grep split string and get last field

Get me last value from delimeter
Grek way

[root@ip-10-31-4-69 inventories]# echo "kube_node_1_111" | grep -o '[^_]*$'
111

OR

Awk way

[root@ip-10-31-4-69 inventories]# echo "kube_node_1123" | awk -F "_" '{print $NF}'
1123

jq cheat sheet

Jq basics

[root@ip-10-31-4-69 inventories]# ./hosts --list | jq '.tag_Role_kube_node'

[
 "kube_node_1"
 ]

Jq remove square brackets [] : use []
Output

 [root@ip-10-31-4-69 inventories]# ./hosts --list | jq '.tag_Role_kube_node[]'
 "kube_node_1"

Jq remove quote “” : use -r
Output

 [root@ip-10-31-4-69 inventories]# ./hosts --list | jq -r '.tag_Role_kube_node[]'
 kube_node_1

Powered by WordPress & Theme by Anders Norén