Tikejhya: Ashish Nepal

Knowledgebase

Category: Uncategorised

jq cheat sheet

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.

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

Chef Basics [Knife]

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.

#save cookbook changes
knife cookbook upload tike_web

#Show role
knife role show web

#list all client
knife node list

# show user specific databags
knife data bag show users ashnep

# show environment specific databags
knife data bag show prod prod_data

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.

#Create cookbook
knife cookbook create filebeats

#test configuration
rubocop cookbooks/filebeats

#Upload cookbook
knife cookbook upload filebeats

#show node data
knife node show ashnep-test

#Chef bootstrap
#bootstrap 10.10.10.1
-N NODENAME
-r RUN_LIST, –run-list RUN_LIST
-E ENVIRONMENT, –environment ENVIRONMENT
-x USERNAME, –ssh-user USERNAME
–use-sudo-password (Perform a bootstrap operation with sudo; specify the password with the -P (or –ssh-password) option)

knife bootstrap 10.10.10.1 -N web1.tikejhya.com -r "role[web]" --environment dev -x tikejhya --sudo --use-sudo-password -i ~/.ssh/my_prv

Magento admin user password hash

# Magento stores user password inside admin_user and hashing is done with some random key
#So here we are resetting password with somepass for user called username

UPDATE admin_user SET password=CONCAT(MD5('qXsomepass'), ':qX') WHERE username = 'username';

Mac OSX port forwarding

Mac OSX port forwarding

echo "rdr pass inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080" | sudo pfctl -ef -

odbc in centos

# centos
yum install mysql-connector-odbc

#ubuntu
apt-get install libmyodbc

root@ip-10-0-1-82:~# odbcinst -q -s
[testdb]
root@ip-10-0-1-82:~# odbcinst -q -d
[PostgreSQL]
[MySQL]
root@ip-10-0-1-82:~# odbcinst -j
unixODBC 2.2.14
DRIVERS…………: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size…….: 8
SQLLEN Size……..: 8
SQLSETPOSIROW Size.: 8
root@ip-10-0-1-82:~# isql -S testdb -U root -P somepassword

checking shared odbc libraries linked to isql for default directories…
strings: ”: No such file
trying /tmp/sql … no
trying /tmp/sql … no
trying /etc … OK
checking odbc.ini files
reading /root/.odbc.ini
[testdb] found in /root/.odbc.ini
found this section:
[testdb]
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
SERVER = localhost
USER = root
PASSWORD = somepassword
PORT = 3306
DATABASE = db2
Charset = UTF8
looking for driver for DSN [testdb] in /root/.odbc.ini
found driver line: ” Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so”
driver “/usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so” found for [testdb] in .odbc.ini
found driver named “/usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so”
/usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so is an executable file
“SERVER” found, not using freetds.conf
SERVER is “localhost”

Configuration looks OK. Connection details:

DSN: testdb
odbc.ini: /root/.odbc.ini
Driver: /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
Server hostname: localhost
Address: 127.0.0.1

Attempting connection as root …
+ isql testdb root somepassword -v
+—————————————+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+—————————————+
SQL>

nginx Restricting Access

Restricting Access using allow deny with satisfy Any.

Access can be allowed or denied based on the IP address of a client or by using HTTP basic authentication.

To allow or deny access from a certain set of addresses, or all addresses, use the allow and deny directives:

location / {
allow 192.168.1.1/24;
allow 127.0.0.1;
deny 192.168.1.2;
deny all;
}

Restricting access with allow deny can be complemented with use of http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html

which allows to use either IP based restriction or User password based authentication. This is one of the key feature in Apache and majority of we want to have simillar use case senario:

location / {
auth_basic "closed site";
auth_basic_user_file conf/htpasswd;
}

So combining this two may look like this:

location / {
satisfy any;

allow 192.168.1.1/24;
allow 127.0.0.1;
deny 192.168.1.2;
deny all;

auth_basic "closed site";
auth_basic_user_file conf/htpasswd;
}

cronjob offset

How to setup cronjob with offset:

# This cron will execute every fifth minute.
1-59/5 * * * * echo "hello i am offsetting 1"
# This cron will execute every fifth minute which starts with 2nd minute hence, it would offset by 1 minute compared to above.
2-59/5 * * * * echo "hello i am offsetting 2"
# This cron will execute every fifth minute which starts with 3rd minute hence, it would offset by 2 minute compared to above.
3-59/5 * * * * echo "hello i am offsetting 3"

This can also be done using sleep 60; sleep 120; sleep 180;

awk values where second coloum matches

awk '$2==5' file

Powered by WordPress & Theme by Anders Norén