Tech C**P
14 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
Sometimes to know your IP address, you have to open a web browser and open a site that gives you the ip address of your system. But what if you are a sysadmin and you don't have access to a browser on Linux server? What if you don't wanna leave your terminal?

Get your IP address from command line using curl:
$ curl ifconfig.co
80.171.524.14

#linux #sysadmin #curl #ifconfig #ip #ip_address #ipv4
You are on a server and all of a sudden you need your public IP address. You can do it using cURL and terminal:
$ curl ifconfig.co
142.17.150.17

The website will just spit out the IP address with no bullshit around it! It is more specifically used by sysadmins.

#linux #sysadmin #curl #ifconfig #ifconfigco
How to check whether your site is served in gzip or not by using cURL linux command:
curl -H "Accept-Encoding: gzip" -I https://www.google.com

If you find the bloew line in the returned response, your site supports gzip:
content-encoding: gzip

NOTE: gzip can speed up your site speed tremendously, sometimes by 90% compression! It also affects your google rank.

#linux #curl #gzip #seo
How to check whether a socks server working or not?

Let's say you have run a socks server on port 8888. Now in order to test the server, you just need to use cURL! You need to provide --socks5 parameter to cURL as below:
curl --socks5 localhost:8888 binfalse.de

If you see some HTML stuff, your server is up & running, but if you see the below error it seems the server is not working properly:
curl: (7) Failed to connect to localhost port 8888: Connection refused

The above error says that port 8888 is not available, you may see different errors based on the server configuration stat. Hope it helps.

#socks5 #socks #socks_server #curl
Apply new basic license on Kibana:

You need to download the license first:
- https://register.elastic.co/xpack_register


The license is a json file that can be applied by cURL, first go to your server where elasticsearch is running and then:

curl -XPUT 'http://172.16.133.102:9200/_xpack/license' -H "Content-Type: application/json" -d @license.json

NOTE: license.json is the file that should be present beside from where you are issuing the cURL command.

#kibana #curl #license #elasticsearch
Get the oldest elasticsearch index:

curl 'http://127.0.0.1:9200/_cat/indices' 2>&1 | awk '{print $3}' | grep "logstash_.*" | sort -t- -k2

DO NOT PANIC! Just enjoy it :)

First of all we use curl to get list of indexes from elasticsearch. By using awk with fetch just the 3rd column of the output, 3rd column refers to your index names (be careful to give your index name as there are internal indexes too and we do not want to purge them). grep command will then filter indexes and outputs those that start by logstash_, if yours are different change it. Finally the sort command sorts the result, but it first gets a delimiter by -t. sort -t- will split the column to TWO columns based on dash (-):

If my index name is logstash_data-20180619, it will exports 2 columns one is logstash_data and the other is 20180619. Now we use -k2 in order to sort based on the second column which is the date of the index.

This is how we can get the oldest elastic search index. I use this for maintenance of ES. In case disk space is almost full, I will delete the oldest elasticsearch index. You can even send a SLACK notification using cURL too.

The possibilities are endless.

Happy bashing :)

#linux #bash #curl #grep #sort #es #elasticsearch #split #awk #script