<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: K Dhanesh</title>
    <description>The latest articles on DEV Community by K Dhanesh (@dhanupreeth).</description>
    <link>https://dev.to/dhanupreeth</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F632251%2F03a1d194-4be1-49ae-bb20-49ee5185a0b9.jpg</url>
      <title>DEV Community: K Dhanesh</title>
      <link>https://dev.to/dhanupreeth</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dhanupreeth"/>
    <language>en</language>
    <item>
      <title>How to create New VM in CLI</title>
      <dc:creator>K Dhanesh</dc:creator>
      <pubDate>Mon, 24 May 2021 19:05:04 +0000</pubDate>
      <link>https://dev.to/dhanupreeth/how-to-create-new-vm-in-cli-4f6f</link>
      <guid>https://dev.to/dhanupreeth/how-to-create-new-vm-in-cli-4f6f</guid>
      <description>&lt;h3&gt;
  
  
  KVM to Create New VM using CLI Commands, Tested in ubuntu 16.04 its working fine
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;virt-install &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--virt-type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;kvm &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--name&lt;/span&gt; centos7 &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--ram&lt;/span&gt; 6144 &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--vcpus&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;8 &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--os-variant&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;rhel7 &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--hvm&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--cdrom&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/RootPartitions/CentOS-7-x86_64-DVD-1810.iso &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--network&lt;/span&gt; &lt;span class="nv"&gt;network&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;default,model&lt;span class="o"&gt;=&lt;/span&gt;virtio &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--graphics&lt;/span&gt; vnc &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--disk&lt;/span&gt; &lt;span class="nv"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/RootPartitions/centos7-0.1.img,size&lt;span class="o"&gt;=&lt;/span&gt;30,bus&lt;span class="o"&gt;=&lt;/span&gt;virtio


&lt;span class="c"&gt;# Spin a New VM with Bridge Network&lt;/span&gt;

&lt;span class="nb"&gt;sudo &lt;/span&gt;virt-install &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--virt-type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;kvm &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--name&lt;/span&gt; centos7 &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--ram&lt;/span&gt; 6144 &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--vcpus&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;8 &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--os-variant&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;rhel7 &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--hvm&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--cdrom&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/RootPartitions/CentOS-7-x86_64-DVD-1810.iso &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--network&lt;/span&gt; &lt;span class="nv"&gt;bridge&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;br0,model&lt;span class="o"&gt;=&lt;/span&gt;virtio &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--graphics&lt;/span&gt; vnc &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--disk&lt;/span&gt; &lt;span class="nv"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/RootPartitions/centos7.img,size&lt;span class="o"&gt;=&lt;/span&gt;30,bus&lt;span class="o"&gt;=&lt;/span&gt;virtio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Basic Virsh Commands
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;virsh list &lt;span class="nt"&gt;--all&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="c"&gt;# to all the VM in the Host Machine &lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;virsh destroy &amp;lt;vm-nam&amp;gt; &lt;span class="c"&gt;# Stopping or Shutting down the VM&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;virsh dumpxml vm-name &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; vm-name.xml &lt;span class="c"&gt;# Export the VM setting in XML Formate&lt;/span&gt;
&lt;span class="nb"&gt;sudo cat &lt;/span&gt;vm-name.xml | &lt;span class="nb"&gt;grep source&lt;/span&gt; &lt;span class="c"&gt;# to list the attached Partition&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;lvremove /partition/name &lt;span class="c"&gt;# remove the LVM Partition &lt;/span&gt;
&lt;span class="nb"&gt;sudo rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; /RootParition/Centos.img &lt;span class="c"&gt;# To remove the .img and .qcow2 partitions&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;virsh undefine &amp;lt;vm-name&amp;gt; &lt;span class="c"&gt;# Removing the VM from the Host Machine, before execute&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;virsh vncdisplay &lt;span class="c"&gt;# to display the VNC port number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to Connect the Private VM from the Local machine
&lt;/h3&gt;

&lt;p&gt;Host Machine should have the Public and Private Network and VM should configured via bridge network from Privat network. &lt;/p&gt;

&lt;p&gt;Using SSH tunnel we can connect the VM, before pls install VNC viewer in your local - &lt;a href="https://www.realvnc.com/en/connect/download/viewer/"&gt;https://www.realvnc.com/en/connect/download/viewer/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From Local Machine&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-L&lt;/span&gt; localhost:5900:VM-IP:VNC-Port-Number username@hostmachine.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;For Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HostMachine: dhanesh.vm-test.com (Public IP)&lt;br&gt;
HostMachine: UserName: dhanesh&lt;br&gt;
VM PrivateIP: 192.168.100.100&lt;br&gt;
VM VNC Port: 12&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-L&lt;/span&gt; localhost:5900:192.168.100.100:5912 dhanesh@dhanesh.vm-test.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally open the VNC viewer and type &lt;code&gt;localhost:5900&lt;/code&gt; you can able to see the VM from your local machine. &lt;/p&gt;

&lt;p&gt;Ensure that all the Network settings are working fine.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>linux</category>
      <category>kvm</category>
    </item>
    <item>
      <title>Wordpress along with Rails app with Apache2 and Passenger
</title>
      <dc:creator>K Dhanesh</dc:creator>
      <pubDate>Thu, 20 May 2021 17:30:33 +0000</pubDate>
      <link>https://dev.to/dhanupreeth/wordpress-along-with-rails-app-with-apache2-and-passenger-1egd</link>
      <guid>https://dev.to/dhanupreeth/wordpress-along-with-rails-app-with-apache2-and-passenger-1egd</guid>
      <description>&lt;h2&gt;
  
  
  Wordpress along with Rails app with Apache2 and Passenger
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Intro
&lt;/h3&gt;

&lt;p&gt;This document helps to run Wordpress blog along with Rails app in a same server and make it available / accessible via Rails App. In this example we want to run a Rails app that accsesible via domain name &lt;a href="http://www.dhanesh-example.com"&gt;www.dhanesh-example.com&lt;/a&gt; and also want to run a Wordpress instance that accessible via /blog.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;user access the &lt;a href="http://www.dhanesh-example.com"&gt;www.dhanesh-example.com&lt;/a&gt; or any paths (except /blog /api), it will refer to the Rails app&lt;/li&gt;
&lt;li&gt;user access the &lt;a href="http://www.dhanesh-eample.com/blog"&gt;www.dhanesh-eample.com/blog&lt;/a&gt; or any paths inside /blog path scope it will refer to wordpress.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Steps
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;New or Running Rails project path /var/www/html/rails_app&lt;/li&gt;
&lt;li&gt;Install passenger gem&lt;/li&gt;
&lt;li&gt;Install apache2 and passenger module&lt;/li&gt;
&lt;li&gt;Create virtual host for Rails app&lt;/li&gt;
&lt;li&gt;Download, Extract, and rename the wordpress folder to blog&lt;/li&gt;
&lt;li&gt;Move the blog folder to /var/www/html/blog and configure our wordpress instance&lt;/li&gt;
&lt;li&gt;Create MySQL database for our wordpress instance&lt;/li&gt;
&lt;li&gt;set WP_HOME and WP_SITEURL wordpress config to &lt;a href="http://www.dhanesh-example.com/blog"&gt;http://www.dhanesh-example.com/blog&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Add gem 'rails-reverse-proxy' to your Gemfile and run bundle install, Commit the Gemfile and Gemfile.lock&lt;/li&gt;
&lt;li&gt;Create controller to handle reverse proxy from Rails to wordpress&lt;/li&gt;
&lt;li&gt;Create new route that will point access to /blog path to our reverse proxy controller.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ADDITIONAL DETAILS
&lt;/h3&gt;

&lt;p&gt;Configure Rails, Passenger, Apache2&lt;/p&gt;

&lt;p&gt;Install passenger gem and continue with installing apache2 passenger module by run passenger-install-apache2-module. Follow any instructions from the installation guide until all requirements met.&lt;/p&gt;

&lt;p&gt;Note: don't forget the important part from the installation guide that will ask you to load passenger module in your apache2 configuration file /etc/apache2/apache2.conf&lt;/p&gt;

&lt;p&gt;Create new virtual host by creating new config file in /etc/apache2/sites-available/dhanesh-example.conf folder. Use this configuration for the virtual host:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;VirtualHost &lt;span class="k"&gt;*&lt;/span&gt;:80&amp;gt;
    ServerName dhanesh-example.com
    ServerAlias www.dhanesh-example.com
    ServerAdmin dhanesh@example.com
    DocumentRoot /var/www/html/rails_app/current/public
    RailsEnv production
    ErrorLog /var/log/apache2/app-name/error.log
    CustomLog /var/log/apache2/app-name/production.log combined
    &amp;lt;Directory &lt;span class="s2"&gt;"/var/www/html/rails_app/current/public"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        Options FollowSymLinks
        Require all granted
    &amp;lt;/Directory&amp;gt;
&amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Wordpress Configuration
&lt;/h3&gt;

&lt;p&gt;Update the wp-config.php set WP_HOME and WP_SITEURL to &lt;a href="http://www.dhanesh-example.com/blog"&gt;http://www.dhanesh-example.com/blog&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;define&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'WP_SITEURL'&lt;/span&gt;, &lt;span class="s1"&gt;'http://dhanesh-example.com/blog'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
define&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'WP_HOME'&lt;/span&gt;,    &lt;span class="s1"&gt;'http://dhanesh-example.com/blog'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
define&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'FS_METHOD'&lt;/span&gt;, &lt;span class="s1"&gt;'direct'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configuring Reverse proxy from Rails to Wordpress
&lt;/h3&gt;

&lt;p&gt;Install rails-reverse-proxy gem&lt;/p&gt;

&lt;p&gt;Create a controller that will handle reverse proxy from Rails to wordpress. In my example, the controller name is WordpressController with the following codes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# app/controllers/wordpress_controller.rb&lt;/span&gt;
class WordpressController &amp;lt; ApplicationController
  include ReverseProxy::Controller
  def index
    reverse_proxy &lt;span class="s2"&gt;"http://dhanesh-example.com:80"&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; |config|
      config.on_missing &lt;span class="k"&gt;do&lt;/span&gt; |code, response|
        redirect_to root_url   and &lt;span class="k"&gt;return
      &lt;/span&gt;end
    end
  end
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could change the &lt;a href="http://dhanesh-example.com:80"&gt;http://dhanesh-example.com:80&lt;/a&gt; part with any host and any port where your wordpress instance running.&lt;/p&gt;

&lt;p&gt;Next, you need to add new route to config/route.rb that will point any request to /blog path in our Rails app to our reverse proxy controller (WordpressController). Here is my config/routes.rb:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Rails.application.routes.draw &lt;span class="k"&gt;do
  &lt;/span&gt;match &lt;span class="s1"&gt;'blog'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'wordpress#index'&lt;/span&gt;, via: &lt;span class="o"&gt;[&lt;/span&gt;:get, :post, :put, :patch, :delete]
  match &lt;span class="s1"&gt;'blog/*path'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'wordpress#index'&lt;/span&gt;, via: &lt;span class="o"&gt;[&lt;/span&gt;:get, :post, :put, :patch, :delete]

  get &lt;span class="s1"&gt;'home/index'&lt;/span&gt;
  root to: &lt;span class="s1"&gt;'home#index'&lt;/span&gt;
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When there is request to /blog path, our Rails app will point it to apache server and looking for a folder with name blog, that's why we need to rename our wordpress folder into blog.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure virtual host for wordpress
&lt;/h3&gt;

&lt;p&gt;Edit the previously created config file in dhanesh-example.conf folder. Add the following configurations to the virtual host:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    Alias /blog /var/www/html/blog
    &amp;lt;Directory /var/www/html/blog&amp;gt;
        Allow From all
        Options +Indexes
        AllowOverride all
    &amp;lt;/Directory&amp;gt;

    &amp;lt;Location /blog&amp;gt;
      PassengerEnabled off
    &amp;lt;/Location&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart the Apache server again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test
&lt;/h3&gt;

&lt;p&gt;dhanesh-example.com it will display rails page and try to access dhanesh-example.com/blog it will point to the wordpress blog&lt;/p&gt;

&lt;h4&gt;
  
  
  Example Vhost Entry
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;IfModule mod_ssl.c&amp;gt;
&amp;lt;VirtualHost *:443&amp;gt;
    RailsEnv production
    ServerName dhanesh-example.com
    #ServerAlias www.dhanesh-example.com
    DocumentRoot "/var/www/html/rails_app/current/public"
    PassengerRuby /home/dhanesh/.rvm/gems/ruby-2.6.3/wrappers/ruby
    #DocumentRoot "/var/www/html"
    ErrorLog "/var/log/apache2/example.com/error.log"
    CustomLog "/var/log/apache2/example.com/access.log" common
    &amp;lt;Directory "/var/www/html/rails_app/current/public"&amp;gt;
    #&amp;lt;Directory "/var/www/html"&amp;gt;
        Options All
        #DirectoryIndex maintenance.html
        AllowOverride All
        Order allow,deny
        Allow from all
    &amp;lt;/Directory&amp;gt;
    Alias /blog /var/www/html/blog
    &amp;lt;Directory /var/www/html/blog&amp;gt;
        Options FollowSymLinks
        AllowOverride Limit Options FileInfo
        DirectoryIndex index.php
        Order allow,deny
        Allow from all
    &amp;lt;/Directory&amp;gt;
    &amp;lt;Directory /var/www/html/blog/wp-content&amp;gt;
        Options FollowSymLinks
        Order allow,deny
        Allow from all
    &amp;lt;/Directory&amp;gt;
    &amp;lt;Location /blog&amp;gt;
        PassengerEnabled off
    &amp;lt;/Location&amp;gt;
    #RewriteEngine on
    #RewriteRule index\.html index.php [NC,R]
    # Remove the www
    #RewriteCond %{HTTP_HOST} ^www.URL$ [NC]
    #RewriteRule ^(.*)$ http://URL/ [R=301,L]
    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/dhanesh-example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/dhanesh-example.com/privkey.pem
&amp;lt;/VirtualHost&amp;gt;
&amp;lt;/IfModule&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Thank you
&lt;/h3&gt;

</description>
      <category>devops</category>
      <category>apache2</category>
      <category>rails</category>
    </item>
    <item>
      <title>Python Script to get the AWS EC2 Instance Details</title>
      <dc:creator>K Dhanesh</dc:creator>
      <pubDate>Thu, 20 May 2021 17:17:23 +0000</pubDate>
      <link>https://dev.to/dhanupreeth/python-script-to-get-the-aws-ec2-instance-details-3mc9</link>
      <guid>https://dev.to/dhanupreeth/python-script-to-get-the-aws-ec2-instance-details-3mc9</guid>
      <description>&lt;p&gt;Used python version 3.7 and Boto3, Kindly configure the AWS IAM Credentials in your local or workstation&lt;/p&gt;

&lt;p&gt;AWS Profile Configuration&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws configure --profile name(my_proile)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import boto3
import sys
import time

session=boto3.Session(profile_name="my_profile", region_name="us-east-1") #boto3 session, aws profile 

ec2_resource=session.resource(service_name="ec2") # resource object method

'''
client object method, commented because this script using resource object method
ec2_client=session.client(service_name="ec2")
'''

#using Resource Object
'''
for each_instances in ec2_resource.instances.all():
    print(each_instances.id, each_instances.state['Name'])
'''

for instance in ec2_resource.instances.all():
     print(
            "Id: {0}\nPlatform: {1}\nType: {2}\nPublic IPv4: {3}\nAMI: {4}\nState: {5}\n".format(
         instance.id, instance.platform, instance.instance_type, instance.public_ip_address, instance.image.id, instance.state
         )
     )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
      <category>aws</category>
      <category>devops</category>
    </item>
    <item>
      <title>Practise the Linux Basic Commands </title>
      <dc:creator>K Dhanesh</dc:creator>
      <pubDate>Thu, 20 May 2021 17:02:51 +0000</pubDate>
      <link>https://dev.to/dhanupreeth/practise-the-linux-basic-commands-31i5</link>
      <guid>https://dev.to/dhanupreeth/practise-the-linux-basic-commands-31i5</guid>
      <description>&lt;h1&gt;
  
  
  Unix Tools
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Bash Commands
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt;                &lt;span class="c"&gt;## Get the Kernel Version&lt;/span&gt;
lsb_release &lt;span class="nt"&gt;-a&lt;/span&gt;          &lt;span class="c"&gt;# Release or Distibution info&lt;/span&gt;
&lt;span class="nb"&gt;cat&lt;/span&gt; /etc/SuSE-release   &lt;span class="c"&gt;# Suse Linux Version Check&lt;/span&gt;
&lt;span class="nb"&gt;cat&lt;/span&gt; /etc/debian_version &lt;span class="c"&gt;# Debian Version check&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Basic Commands to know the Server status
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;uptime&lt;/span&gt;                  &lt;span class="c"&gt;# it will shows how long the system has been running&lt;/span&gt;
&lt;span class="nb"&gt;hostname&lt;/span&gt;                &lt;span class="c"&gt;# System Host Name&lt;/span&gt;
&lt;span class="nb"&gt;hostname&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt;             &lt;span class="c"&gt;# To Display to the ip address of the Host, Linux based distribution&lt;/span&gt;
man hier                &lt;span class="c"&gt;# File system hierarchy Description&lt;/span&gt;
last reboot             &lt;span class="c"&gt;# to know the system reboot history&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Hardware informations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Kernel Detected HW
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dmesg                   &lt;span class="c"&gt;# Detect Hardware and Boot messages&lt;/span&gt;
lsdev                   &lt;span class="c"&gt;# Info about the installed Hardware like PCI Card&lt;/span&gt;
&lt;span class="nb"&gt;dd &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/mem &lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1k &lt;span class="nv"&gt;skip&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;768 &lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;256 2&amp;gt;/dev/null | strings &lt;span class="nt"&gt;-n&lt;/span&gt; 8  &lt;span class="c"&gt;# Read BIOS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Linux
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; /proc/cpuinfo                &lt;span class="c"&gt;# CPU Model&lt;/span&gt;
&lt;span class="nb"&gt;cat&lt;/span&gt; /proc/meminfo                &lt;span class="c"&gt;# Hardware Memory&lt;/span&gt;
&lt;span class="nb"&gt;grep &lt;/span&gt;MemTotal /proc/meminfo      &lt;span class="c"&gt;# Physical Memory&lt;/span&gt;
watch &lt;span class="nt"&gt;-n1&lt;/span&gt; &lt;span class="s1"&gt;'cat /proc/interrupts'&lt;/span&gt; &lt;span class="c"&gt;# watch changecable interrupts&lt;/span&gt;
free &lt;span class="nt"&gt;-m&lt;/span&gt;                          &lt;span class="c"&gt;# To know the used &amp;amp; free memory ( -m for MB)&lt;/span&gt;
&lt;span class="nb"&gt;cat&lt;/span&gt; /proc/devices                &lt;span class="c"&gt;# Configured devices&lt;/span&gt;
lspci &lt;span class="nt"&gt;-tv&lt;/span&gt;                        &lt;span class="c"&gt;# PCI Device info&lt;/span&gt;
lsusb &lt;span class="nt"&gt;-tv&lt;/span&gt;                        &lt;span class="c"&gt;# USB Device info&lt;/span&gt;
lshal                            &lt;span class="c"&gt;# List all devices with properties&lt;/span&gt;
dmidecode                        &lt;span class="c"&gt;# DMI/SMBIOS: hw info from the BIOS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Free BSD
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sysctl hw.model                 &lt;span class="c"&gt;# CPU Model&lt;/span&gt;
sysctl hw                       &lt;span class="c"&gt;# More information about hardware&lt;/span&gt;
sysctl hw.ncpu                  &lt;span class="c"&gt;# No. of active CPU's Installed&lt;/span&gt;
sysctl vm                       &lt;span class="c"&gt;# Memory Usage&lt;/span&gt;
sysctl hw.realmem               &lt;span class="c"&gt;# Hardware Memory (Physical)&lt;/span&gt;
sysctl &lt;span class="nt"&gt;-a&lt;/span&gt; | &lt;span class="nb"&gt;grep &lt;/span&gt;mem            &lt;span class="c"&gt;# Kernel memory settings and info&lt;/span&gt;
sysctl dev                      &lt;span class="c"&gt;# Configured devices&lt;/span&gt;
pciconf &lt;span class="nt"&gt;-l&lt;/span&gt; &lt;span class="nt"&gt;-cv&lt;/span&gt;                  &lt;span class="c"&gt;# PCI Device info&lt;/span&gt;
usbdevs &lt;span class="nt"&gt;-v&lt;/span&gt;                      &lt;span class="c"&gt;# USB Device info&lt;/span&gt;
atacontrol list                 &lt;span class="c"&gt;# ATA Device info&lt;/span&gt;
camcontrol devlist &lt;span class="nt"&gt;-v&lt;/span&gt;           &lt;span class="c"&gt;# SCSI Device info&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Load, Statistics and Messages
&lt;/h3&gt;

&lt;p&gt;Folowing Commands are useful to find out what is going on the system realtime.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;top                             &lt;span class="c"&gt;# display &amp;amp; update the top CPU processes&lt;/span&gt;
mpstat 1                        &lt;span class="c"&gt;# display processors related statistics&lt;/span&gt;
vmstat 2                        &lt;span class="c"&gt;# virtual memory statistics&lt;/span&gt;
iostat 2                        &lt;span class="c"&gt;# I/O statistics - 2sec intervals&lt;/span&gt;
systat &lt;span class="nt"&gt;-vmstat&lt;/span&gt; 1                &lt;span class="c"&gt;# system statistics - 1sec intervals&lt;/span&gt;
systat &lt;span class="nt"&gt;-tcp&lt;/span&gt; 1                   &lt;span class="c"&gt;# tcp connections (try also -ip)&lt;/span&gt;
systat &lt;span class="nt"&gt;-netstat&lt;/span&gt; 1               &lt;span class="c"&gt;# active network connections - BSD&lt;/span&gt;
systat &lt;span class="nt"&gt;-ifstat&lt;/span&gt; 1                &lt;span class="c"&gt;# network traffic through active interfaces - BSD&lt;/span&gt;
systat &lt;span class="nt"&gt;-iostat&lt;/span&gt; 1                &lt;span class="c"&gt;# CPU and Disk throughput - BSD&lt;/span&gt;
ipcs &lt;span class="nt"&gt;-a&lt;/span&gt;                         &lt;span class="c"&gt;# info on system V interprocess&lt;/span&gt;
&lt;span class="nb"&gt;tail&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; 500 /var/log/messages   &lt;span class="c"&gt;# Last 500 Kernel/syslog messages&lt;/span&gt;
&lt;span class="nb"&gt;tail&lt;/span&gt; /var/log/warn              &lt;span class="c"&gt;# System Warnings messages see syslog.conf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Users
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;id&lt;/span&gt;                                                  &lt;span class="c"&gt;# To display the active user ID with login &amp;amp; group&lt;/span&gt;
last                                                &lt;span class="c"&gt;# To know the last logins on the server&lt;/span&gt;
&lt;span class="nb"&gt;who &lt;/span&gt;or w                                            &lt;span class="c"&gt;# Who is logged on the server currently in simple type "w"&lt;/span&gt;
groupadd admin                                      &lt;span class="c"&gt;# Adding group "admin"&lt;/span&gt;
useradd &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"Dhanesh Kumar"&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; admin &lt;span class="nt"&gt;-m&lt;/span&gt; colin        &lt;span class="c"&gt;# Creating user "Dhanesh Kumar", with "admin" group&lt;/span&gt;
usermod &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-G&lt;/span&gt; &amp;lt;group&amp;gt; &amp;lt;user&amp;gt;                        &lt;span class="c"&gt;# Adding existing user to the group - Debian Based&lt;/span&gt;
groupmod &lt;span class="nt"&gt;-A&lt;/span&gt; &amp;lt;user&amp;gt; &amp;lt;group&amp;gt;                          &lt;span class="c"&gt;# Adding existing user to the group - Suse Linux&lt;/span&gt;
userdel dhanesh                                     &lt;span class="c"&gt;# delete the user "dhanesh" (linux / Solaris)&lt;/span&gt;
adduser dhanesh                                     &lt;span class="c"&gt;# FreeBSD add user joe (interactive)&lt;/span&gt;
rmuser dhanesh                                      &lt;span class="c"&gt;# FreeBSD delete user joe (interactive)&lt;/span&gt;
pw groupadd admin                                   &lt;span class="c"&gt;# Use pw on FreeBSD&lt;/span&gt;
pw groupmod admin &lt;span class="nt"&gt;-m&lt;/span&gt; newmember                      &lt;span class="c"&gt;# Add a new member to a group&lt;/span&gt;
pw useradd dhanesh &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"Dhanesh Kumar"&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; admin &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; /bin/tcsh
pw userdel dhanesh&lt;span class="p"&gt;;&lt;/span&gt; pw groupdel admin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;/etc/shadow - Encrypted passwords are stored&lt;/p&gt;

&lt;p&gt;Temporarily prevent system logings for all user except ROOT user, with nologin.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Apologies no login now"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/nologin     &lt;span class="c"&gt;#(linux)&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Apologies no login now"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /var/run/nologin &lt;span class="c"&gt;#(FreeBSD)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Limits in Linux
&lt;/h3&gt;

&lt;p&gt;Some application requires higer limits on open files and sockets (like a proxy web server, database). The default limits are usually too low.&lt;/p&gt;

&lt;p&gt;Shell/Script&lt;/p&gt;

</description>
      <category>linux</category>
      <category>devops</category>
    </item>
    <item>
      <title>Python Script to get the Docker Containers status</title>
      <dc:creator>K Dhanesh</dc:creator>
      <pubDate>Mon, 17 May 2021 04:18:53 +0000</pubDate>
      <link>https://dev.to/dhanupreeth/python-script-to-get-the-docker-containers-status-2bmc</link>
      <guid>https://dev.to/dhanupreeth/python-script-to-get-the-docker-containers-status-2bmc</guid>
      <description>&lt;h3&gt;
  
  
  Used docker-py SDK
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Installed using pip command
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install docker-py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  &lt;strong&gt;Python Script&lt;/strong&gt;
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os
import datetime
from docker import Client

cli = Client(base_url='unix://var/run/docker.sock')
containers = cli.containers()
for container in range(len(containers)):
 for key in containers[container]:
    print(containers[container][key])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  # Output
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;b8c2a832a4f107b86981d3b346d5627e0554312465fde358f1072b61cc940961
['/etcd']
quay.io/coreos/etcd:v2.2.1
sha256:142eb4c815648ddd1146ce61f85ee577fce794a54489873134b2d9714f396ac6
/etcd -name etcd0 -advertise-client-urls http://localhost:2379,http://localhost:4001 -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 -initial-advertise-peer-urls http://localhost:2380 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster-1 -initial-cluster etcd0=http://localhost:2380 -initial-cluster-state new
1618796211
[{'IP': '0.0.0.0', 'PrivatePort': 2379, 'PublicPort': 2379, 'Type': 'tcp'}, {'IP': '0.0.0.0', 'PrivatePort': 2380, 'PublicPort': 2380, 'Type': 'tcp'}, {'IP': '0.0.0.0', 'PrivatePort': 4001, 'PublicPort': 4001, 'Type': 'tcp'}, {'PrivatePort': 7001, 'Type': 'tcp'}]
{}
running
Up 4 days
{'NetworkMode': 'default'}
{'Networks': {'bridge': {'IPAMConfig': None, 'Links': None, 'Aliases': None, 'NetworkID': '6e5820ead0cfa5c34baee87737f99e5b2b05601d02435760631a914815e0fcb8', 'EndpointID': 'efe94e05a72f0197f891bb49ec6b4882d8da72fc10819cdc38831bbf145001df', 'Gateway': '172.17.0.1', 'IPAddress': '172.17.0.2', 'IPPrefixLen': 16, 'IPv6Gateway': '', 'GlobalIPv6Address': '', 'GlobalIPv6PrefixLen': 0, 'MacAddress': '02:42:ac:11:00:02', 'DriverOpts': None}}}
[{'Type': 'bind', 'Source': '/usr/share/ca-certificates', 'Destination': '/etc/ssl/certs', 'Mode': '', 'RW': True, 'Propagation': 'rprivate'}]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>docker</category>
      <category>python</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
