<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>DGPLUG &amp;mdash; sandeepk</title>
    <link>https://blogs.dgplug.org/sandeepk/tag:DGPLUG</link>
    <description></description>
    <pubDate>Sun, 19 Apr 2026 06:17:05 +0000</pubDate>
    <item>
      <title>sh like infix syntax using Pipes(|) in Python</title>
      <link>https://blogs.dgplug.org/sandeepk/sh-like-infix-syntax-using-pipes-in-python</link>
      <description>&lt;![CDATA[Today, we are going to see how we can use | operator in our python code to achieve clean code. &#xA;&#xA;Here is the code where we have used map and filter for a specific operation.&#xA;In [1]: arr = [11, 12, 14, 15, 18]&#xA;In [2]: list(map(lambda x: x  2, filter(lambda x: x%2 ==1, arr)))&#xA;Out[2]: [22, 30]&#xA;The same code with Pipes.&#xA;In [1]: from pipe import select, where&#xA;In [2]: arr = [11, 12, 14, 15, 18]&#xA;In [3]: list(arr | where (lambda x: x%2 ==1) | select(lambda x:x 2))&#xA;Out[3]: [22, 30]&#xA;Pipes passes the result of one function to another function, have inbuilt pipes method like select, where, tee, traverse. &#xA;&#xA;Install Pipe&#xA;    pip install pipe&#xA;traverse&#xA;Recursively unfold iterable:&#xA; In [12]: arr = [[1,2,3], [3,4,[56]]]&#xA;In [13]: list(arr | traverse)&#xA;Out[13]: [1, 2, 3, 3, 4, 56]&#xA;select()&#xA; An alias for map().&#xA;In [1]: arr = [11, 12, 14, 15, 18]&#xA;In [2]: list(filter(lambda x: x%2 ==1, arr))&#xA;Out[2]: [11, 15]&#xA;where()&#xA;Only yields the matching items of the given iterable:&#xA;In [1]: arr = [11, 12, 14, 15, 18]&#xA;In [2]: list(arr | where(lambda x: x % 2 == 0))&#xA;Out[2]: [12, 14, 18]&#xA;sort()&#xA;Like Python&#39;s built-in &#34;sorted&#34; primitive. Allows cmp (Python 2.x&#xA;only), key, and reverse arguments. By default, sorts using the&#xA;identity function as the key.&#xA;In [1]:  &#39;&#39;.join(&#34;python&#34; | sort)&#xA;Out[1]:  &#39;hnopty&#39;&#xA;reverse&#xA;Like Python&#39;s built-in &#34;reversed&#34; primitive.&#xA;In [1]:  list([1, 2, 3] | reverse)&#xA;Out[1]:   [3, 2, 1]&#xA;strip&#xA;Like Python&#39;s strip-method for str.&#xA;In [1]:  &#39;  abc   &#39; | strip&#xA;Out[1]:  &#39;abc&#39;&#xA;&#xA;That&#39;s all for today, In this blog you have seen how to install the Pipe and use the Pipe to write clean and short code using inbuilt pipes, you can check more over here&#xA;&#xA;Cheers!&#xA;&#xA;100DaysToOffload&#xA;Python&#xA;DGPLUG]]&gt;</description>
      <content:encoded><![CDATA[<p>Today, we are going to see how we can use <em>|</em> operator in our python code to achieve clean code.</p>

<p>Here is the code where we have used map and filter for a specific operation.</p>

<pre><code class="language-python">In [1]: arr = [11, 12, 14, 15, 18]
In [2]: list(map(lambda x: x * 2, filter(lambda x: x%2 ==1, arr)))
Out[2]: [22, 30]
</code></pre>

<p>The same code with Pipes.</p>

<pre><code>In [1]: from pipe import select, where
In [2]: arr = [11, 12, 14, 15, 18]
In [3]: list(arr | where (lambda x: x%2 ==1) | select(lambda x:x *2))
Out[3]: [22, 30]
</code></pre>

<p>Pipes passes the result of one function to another function, have inbuilt pipes method like <strong>select</strong>, <strong>where</strong>, <strong>tee</strong>, <strong>traverse</strong>.</p>

<h3 id="install-pipe">Install Pipe</h3>

<pre><code class="language-shell">&gt;&gt; pip install pipe
</code></pre>

<h3 id="traverse">traverse</h3>

<p>Recursively unfold iterable:</p>

<pre><code class="language-python">In [12]: arr = [[1,2,3], [3,4,[56]]]
In [13]: list(arr | traverse)
Out[13]: [1, 2, 3, 3, 4, 56]
</code></pre>

<h3 id="select">select()</h3>

<p> An alias for map().</p>

<pre><code class="language-python">In [1]: arr = [11, 12, 14, 15, 18]
In [2]: list(filter(lambda x: x%2 ==1, arr))
Out[2]: [11, 15]
</code></pre>

<h3 id="where">where()</h3>

<p>Only yields the matching items of the given iterable:</p>

<pre><code class="language-python">In [1]: arr = [11, 12, 14, 15, 18]
In [2]: list(arr | where(lambda x: x % 2 == 0))
Out[2]: [12, 14, 18]
</code></pre>

<h3 id="sort">sort()</h3>

<p>Like Python&#39;s built-in “sorted” primitive. Allows cmp (Python 2.x
only), key, and reverse arguments. By default, sorts using the
identity function as the key.</p>

<pre><code class="language-python">In [1]:  &#39;&#39;.join(&#34;python&#34; | sort)
Out[1]:  &#39;hnopty&#39;
</code></pre>

<h3 id="reverse">reverse</h3>

<p>Like Python&#39;s built-in “reversed” primitive.</p>

<pre><code class="language-python">In [1]:  list([1, 2, 3] | reverse)
Out[1]:   [3, 2, 1]
</code></pre>

<h3 id="strip">strip</h3>

<p>Like Python&#39;s strip-method for str.</p>

<pre><code class="language-python">In [1]:  &#39;  abc   &#39; | strip
Out[1]:  &#39;abc&#39;
</code></pre>

<p>That&#39;s all for today, In this blog you have seen how to install the Pipe and use the Pipe to write clean and short code using inbuilt pipes, you can check more over <a href="https://github.com/JulienPalard/Pipe#existing-pipes-in-this-module" rel="nofollow">here</a></p>

<p>Cheers!</p>

<p><a href="/sandeepk/tag:100DaysToOffload" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">100DaysToOffload</span></a>
<a href="/sandeepk/tag:Python" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Python</span></a>
<a href="/sandeepk/tag:DGPLUG" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">DGPLUG</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/sh-like-infix-syntax-using-pipes-in-python</guid>
      <pubDate>Mon, 29 Nov 2021 14:18:04 +0000</pubDate>
    </item>
    <item>
      <title>Profiling Django Application</title>
      <link>https://blogs.dgplug.org/sandeepk/profiling-django-application</link>
      <description>&lt;![CDATA[My work required me to profile one of our Django applications, to help identify the point in the application which we can improve to reach our North Star. So, I thought it will be great to share my learning and tools, that I have used to get the job done.&#xA;&#xA;What is Profiling?&#xA;Profiling) is a measure of the time or memory consumption of the running program. This data further can be used for program optimization.&#xA;&#xA;They are many tools/libraries out there which can be used to do the job. I have found these helpful.&#xA;&#xA;Apache JMeter&#xA;It is open-source software, which is great to load and performance test web applications. It&#39;s easy to set up and can be configured for what we want in the result report.&#xA;&#xA;Pyinstrument&#xA;Pyinstrument is a Python profiler that offers a Django middleware to record the profiling. The profiler generates profile data for every request. The PYINSTRUMENTPROFILEDIR contains a directory that stores the profile data, which is in HTML format. You can check how it works over here&#xA;&#xA;Django Query Count&#xA;Django Query Count is a middleware that prints the number of database queries made during the request processing. There are two possible settings for this, which can be found here&#xA;&#xA;Django Silk&#xA;Django Silk is middleware for intercepting Requests/Responses. We can profile a block of code or functions, either manually or dynamically. It also has a user interface for inspection and visualization &#xA;&#xA;So, here are some of the tools which can be of great help in profiling your code and putting your effort in the right direction of optimization applications.&#xA;&#xA;Cheers!&#xA;&#xA;100DaysToOffload&#xA;Python&#xA;DGPLUG&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>My work required me to profile one of our Django applications, to help identify the point in the application which we can improve to reach our North Star. So, I thought it will be great to share my learning and tools, that I have used to get the job done.</p>

<h2 id="what-is-profiling">What is Profiling?</h2>

<p><a href="https://en.wikipedia.org/wiki/Profiling_(computer_programming)" rel="nofollow">Profiling</a> is a measure of the time or memory consumption of the running program. This data further can be used for program optimization.</p>

<p>They are many tools/libraries out there which can be used to do the job. I have found these helpful.</p>

<h2 id="apache-jmeter-https-jmeter-apache-org"><a href="https://jmeter.apache.org/" rel="nofollow">Apache JMeter</a></h2>

<p>It is open-source software, which is great to load and performance test web applications. It&#39;s easy to set up and can be configured for what we want in the result report.</p>

<h2 id="pyinstrument-https-pyinstrument-readthedocs-io-en-latest-home-html"><a href="https://pyinstrument.readthedocs.io/en/latest/home.html" rel="nofollow">Pyinstrument</a></h2>

<p>Pyinstrument is a Python profiler that offers a Django middleware to record the profiling. The profiler generates profile data for every request. The PYINSTRUMENT<em>PROFILE</em>DIR contains a directory that stores the profile data, which is in HTML format. You can check how it works over <a href="https://pyinstrument.readthedocs.io/en/latest/how-it-works.html" rel="nofollow">here</a></p>

<h2 id="django-query-count-https-github-com-bradmontgomery-django-querycount"><a href="https://github.com/bradmontgomery/django-querycount" rel="nofollow">Django Query Count</a></h2>

<p>Django Query Count is a middleware that prints the number of database queries made during the request processing. There are two possible settings for this, which can be found <a href="https://github.com/bradmontgomery/django-querycount#settings" rel="nofollow">here</a></p>

<h2 id="django-silk-https-github-com-jazzband-django-silk"><a href="https://github.com/jazzband/django-silk" rel="nofollow">Django Silk</a></h2>

<p>Django Silk is middleware for intercepting Requests/Responses. We can profile a block of code or functions, either manually or dynamically. It also has a user interface for inspection and visualization</p>

<p>So, here are some of the tools which can be of great help in profiling your code and putting your effort in the right direction of optimization applications.</p>

<p>Cheers!</p>

<p><a href="/sandeepk/tag:100DaysToOffload" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">100DaysToOffload</span></a>
<a href="/sandeepk/tag:Python" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Python</span></a>
<a href="/sandeepk/tag:DGPLUG" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">DGPLUG</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/profiling-django-application</guid>
      <pubDate>Sun, 28 Nov 2021 12:00:31 +0000</pubDate>
    </item>
    <item>
      <title>Python : Data Class</title>
      <link>https://blogs.dgplug.org/sandeepk/python-data-class</link>
      <description>&lt;![CDATA[A data class is a class containing data only, from Python3.7 we can define a data class with the help of decorator @dataclass, which build the class with the basic functionality like init , repr, eq and more special methods.&#xA;&#xA;Let see how to define your data class with the decorator @dataclass&#xA;from dataclasses import dataclass&#xA;&#xA;@dataclass&#xA;class Batch:&#xA;    sku: int&#xA;    name: str&#xA;    qty: int&#xA;&#xA;      Batch(1, &#39;desk&#39;, 100)&#xA;Batch(sku=1, name=&#39;desk&#39;, qty=100)&#xA;We can also add the default value to the data class, which works exactly as if we do in the init  method of regular class. As you have noticed in the above we have defined the fields with type hints, which is kind of mandatory thing in the data class, if you do not do it will not take the field in your data class.&#xA;&#xA;@dataclass&#xA;class Batch:&#xA;    sku: int = 1&#xA;    name: str = &#39;desk&#39;&#xA;    qty: int = 100&#xA;&#xA;if you don&#39;t want to explicity type the fields you can use any&#xA;from typing import Any&#xA;class AnyBatch:&#xA;    sku: Any&#xA;    name: Any = &#39;desk&#39;&#xA;    qty: Any = 100&#xA;&#xA;If you want to define mutable default value in data class, it can be done with the help of defaultfactory and field. Field() is used to customize each field in data class, different parameter that can be passed to field are defaultfactory, compare, hash, init, you can check about them over here &#xA;from dataclasses import dataclass, field&#xA;from typing import List&#xA;&#xA;@dataclass()&#xA;class Batch:&#xA;    sku: int&#xA;    name: str&#xA;    qty: int = 0&#xA;    creator: List[str] = field(default_factory=function/mutable value)&#xA;&#xA;Immutable Data Class&#xA;we can also define our data class as immutable by setting frozen=True, which basically means we cannot assign value to the fields after creation&#xA;@dataclass(frozen=True)&#xA;class Batch:&#xA;    sku: int&#xA;    name: str&#xA;    qty: int = 0&#xA;&#xA;      b = Batch(12, &#39;desk&#39;, 100)&#xA;      b.qty &#xA;100&#xA;      b.qty = 90&#xA;dataclasses.FrozenInstanceError: cannot assign to field &#39;qty&#39;&#xA;Data class saves us from writing boilerplate code, help us to focus on logic, this new feature of Python3.7 is great, so what waiting for go and right some data classes.&#xA;&#xA;Cheers!&#xA;&#xA;100DaysToOffload&#xA;Python&#xA;DataClass&#xA;TIL&#xA;DGPLUG&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>A data class is a class containing data only, from Python3.7 we can define a data class with the help of decorator <code>@dataclass</code>, which build the class with the basic functionality like <code>__init__</code> , <code>__repr__</code>, <code>__eq__</code> and more special methods.</p>

<p>Let see how to define your data class with the decorator <code>@dataclass</code></p>

<pre><code class="language-python">from dataclasses import dataclass

@dataclass
class Batch:
    sku: int
    name: str
    qty: int

&gt;&gt;&gt; Batch(1, &#39;desk&#39;, 100)
Batch(sku=1, name=&#39;desk&#39;, qty=100)
</code></pre>

<p>We can also add the default value to the data class, which works exactly as if we do in the <code>__init__</code>  method of regular class. As you have noticed in the above we have defined the fields with type hints, which is kind of mandatory thing in the data class, if you do not do it will not take the field in your data class.</p>

<pre><code class="language-python">@dataclass
class Batch:
    sku: int = 1
    name: str = &#39;desk&#39;
    qty: int = 100

# if you don&#39;t want to explicity type the fields you can use any
from typing import Any
class AnyBatch:
    sku: Any
    name: Any = &#39;desk&#39;
    qty: Any = 100

</code></pre>

<p>If you want to define mutable default value in data class, it can be done with the help of <code>default_factory</code> and <code>field</code>. Field() is used to customize each field in data class, different parameter that can be passed to field are <code>default_factory</code>, <code>compare</code>, <code>hash</code>, <code>init</code>, you can check about them over <a href="https://docs.python.org/3/library/dataclasses.html#dataclasses.field" rel="nofollow">here </a></p>

<pre><code class="language-python">from dataclasses import dataclass, field
from typing import List

@dataclass()
class Batch:
    sku: int
    name: str
    qty: int = 0
    creator: List[str] = field(default_factory=&lt;function/mutable value&gt;)
</code></pre>

<p><strong>Immutable Data Class</strong>
we can also define our data class as immutable by setting <code>frozen=True</code>, which basically means we cannot assign value to the fields after creation</p>

<pre><code class="language-python">@dataclass(frozen=True)
class Batch:
    sku: int
    name: str
    qty: int = 0

&gt;&gt;&gt; b = Batch(12, &#39;desk&#39;, 100)
&gt;&gt;&gt; b.qty 
100
&gt;&gt;&gt; b.qty = 90
dataclasses.FrozenInstanceError: cannot assign to field &#39;qty&#39;
</code></pre>

<p>Data class saves us from writing boilerplate code, help us to focus on logic, this new feature of Python3.7 is great, so what waiting for go and right some data classes.</p>

<p>Cheers!</p>

<p><a href="/sandeepk/tag:100DaysToOffload" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">100DaysToOffload</span></a>
<a href="/sandeepk/tag:Python" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Python</span></a>
<a href="/sandeepk/tag:DataClass" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">DataClass</span></a>
<a href="/sandeepk/tag:TIL" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">TIL</span></a>
<a href="/sandeepk/tag:DGPLUG" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">DGPLUG</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/python-data-class</guid>
      <pubDate>Fri, 03 Sep 2021 12:54:52 +0000</pubDate>
    </item>
    <item>
      <title>Ansible: Group and Group of Group&#39;s in Inventory</title>
      <link>https://blogs.dgplug.org/sandeepk/ansible-group-and-group-of-groups-in-inventory</link>
      <description>&lt;![CDATA[Inventory(Hosts) file contains the information of the Ansible nodes. We can group based on our use case like web servers, DB servers and uses these groups to execute commands on them. But you have to create a group in the inventory file, let see how to do that.&#xA;&#xA;[webserver]&#xA;IPADDRESS1&#xA;IPADDRESS2&#xA;IPADDRESS3&#xA;&#xA;[webserverduck]&#xA;IPADDRESS1&#xA;&#xA;[dbserver]&#xA;IPADDRESS1&#xA;IPADDRESS2&#xA;IPADDRESS3&#xA;&#xA;[clientduck:children]&#xA;dbserver&#xA;webserverduck&#xA;You can even assign variable nodes or group wise in inventory file&#xA;[webserverduck:vars]&#xA;ansibleconnection=ssh&#xA;ansibleuser=myotheruser&#xA;gatherfact=no&#xA;&#xA;[dbserver]&#xA;IPADDRESS1 ansibleuser=myuser&#xA;IPADDRESS2&#xA;IPADDRESS3&#xA;Cheers!&#xA;&#xA;#100DaysToOffload #Ansible #dgplug&#xA;&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>Inventory(Hosts) file contains the information of the Ansible nodes. We can group based on our use case like web servers, DB servers and uses these groups to execute commands on them. But you have to create a group in the inventory file, let see how to do that.</p>

<pre><code class="language-YML">[webserver]
IP_ADDRESS_1
IP_ADDRESS_2
IP_ADDRESS_3

[webserverduck]
IP_ADDRESS_1

[dbserver]
IP_ADDRESS_1
IP_ADDRESS_2
IP_ADDRESS_3

[clientduck:children]
dbserver
webserverduck
</code></pre>

<p>You can even assign variable nodes or group wise in inventory file</p>

<pre><code class="language-YML">[webserverduck:vars]
ansible_connection=ssh
ansible_user=myotheruser
gather_fact=no


[dbserver]
IP_ADDRESS_1 ansible_user=myuser
IP_ADDRESS_2
IP_ADDRESS_3
</code></pre>

<p>Cheers!</p>

<p><a href="/sandeepk/tag:100DaysToOffload" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">100DaysToOffload</span></a> <a href="/sandeepk/tag:Ansible" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Ansible</span></a> <a href="/sandeepk/tag:dgplug" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">dgplug</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/ansible-group-and-group-of-groups-in-inventory</guid>
      <pubDate>Wed, 23 Jun 2021 15:10:09 +0000</pubDate>
    </item>
    <item>
      <title>Ansible Architecture</title>
      <link>https://blogs.dgplug.org/sandeepk/ansible-architecture</link>
      <description>&lt;![CDATA[Ansible Architecture&#xA;&#xA;What is Ansible&#xA;Ansible is a simple IT automation tool that make application&#xA;and system easier to deploy and maintain. With the help of Ansible, you can automate task like network configuration, code deployment and cloud management. Ansible is an agent less  system, which means that you don&#39;t need to install any software on the client system.&#xA;&#xA;Inventory&#xA;Inventory file is the one which contains the lists of the host servers  on which Ansible works, it can be the IP Addresses, Domain name ...&#xA;&#xA;Hosts&#xA;It contains the IP addresses or Fully qualified domain name of the node servers which you want to configure.&#xA;&#xA;Ansible.cfg&#xA;This file contains the configuration for the Ansible, like the path of the Inventory file and values for the default variable in the Ansible&#xA;&#xA;Ansible Nodes&#xA;Ansible&#39;s nodes are the client system on which we want to execute, deploy or maintain the code(servers on which we want to work).&#xA;&#xA;Ansible Engine&#xA;Ansible engine/master/controller from which we manage all the server nodes.&#xA;&#xA;Cheers!&#xA;&#xA;#100DaysToOffload #Ansible #dgplug&#xA;&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p><img src="https://raw.githubusercontent.com/Skchoudhary/blog-asset/master/dgplug-blog/ansible-arch.png" alt="Ansible Architecture" title="Ansible Architecture"></p>

<p><strong>What is Ansible</strong>
Ansible is a simple IT automation tool that make application
and system easier to deploy and maintain. With the help of Ansible, you can automate task like network configuration, code deployment and cloud management. Ansible is an agent less  system, which means that you don&#39;t need to install any software on the client system.</p>

<p><strong>Inventory</strong>
Inventory file is the one which contains the lists of the host servers  on which Ansible works, it can be the IP Addresses, Domain name ...</p>

<p><strong>Hosts</strong>
It contains the IP addresses or Fully qualified domain name of the node servers which you want to configure.</p>

<p><strong>Ansible.cfg</strong>
This file contains the configuration for the Ansible, like the path of the Inventory file and values for the default variable in the Ansible</p>

<p><strong>Ansible Nodes</strong>
Ansible&#39;s nodes are the client system on which we want to execute, deploy or maintain the code(servers on which we want to work).</p>

<p><strong>Ansible Engine</strong>
Ansible engine/master/controller from which we manage all the server nodes.</p>

<p>Cheers!</p>

<p><a href="/sandeepk/tag:100DaysToOffload" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">100DaysToOffload</span></a> <a href="/sandeepk/tag:Ansible" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Ansible</span></a> <a href="/sandeepk/tag:dgplug" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">dgplug</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/ansible-architecture</guid>
      <pubDate>Wed, 16 Jun 2021 15:52:26 +0000</pubDate>
    </item>
    <item>
      <title>Shell: Day #5</title>
      <link>https://blogs.dgplug.org/sandeepk/shell-day-5</link>
      <description>&lt;![CDATA[Today go through the commands to monitor processes and how to handle them&#xA;&#xA;ps - It reports the snapshot of the current process&#xA;init- It the parent process of all the processes.&#xA;pstree - Same as ps but list the process in form of tree with more details.&#xA;top- List down all the process running, update the snapshot after a while.&#xA;Kill - it signals the process &#xA;     INT - 2 -Interrupt, stop running&#xA;     TERM - 15 - ask a process to exit gracefully&#xA;     KILL - 9 - force the process to stop running &#xA;     TSTP - 18 - request the process to stop temporarily&#xA;     HUP - 1 - Hang up &#xA;nice - Every process run has priority and with nice we can control this priority, it ranges from +19(very nice) to -20(not very nice) decreased niceness higher the priority&#xA;renice- change the priority of the existing process&#xA;&#xA;    top&#xA;PID  User  PR  NI  VIRT     RES     SHR     S  %CPU %MEM Time+ Command&#xA;3911 user  20   0 2855988 206872 141304 S  72.2  2.6   7:15.09 Web Content                                                                       &#xA;31980 user  20   0 3703988 509176 188188 S  33.3  6.3  49:36.10 firefox                                                                           &#xA; 2839 user  20   0 2834092 191744 128268 S  27.8  2.4  16:13.39 Web Content    &#xA;&#xA;    ps&#xA;  PID TTY          TIME CMD&#xA; 2418 pts/2    00:00:00 zsh&#xA; 4318 pts/2    00:00:00 ps&#xA;&#xA;    pstree | less&#xA;systemd-+-NetworkManager-+-dhclient&#xA;        |                |-dnsmasq---dnsmasq&#xA;        |                |-{gdbus}&#xA;        |                `-{gmain}&#xA;        |-accounts-daemon-+-{gdbus}&#xA;        |                 `-{gmain}&#xA;        |-acpid&#xA;        |-agetty&#xA;        |-apache2---2[apache2---26[{apache2}]]&#xA;        |-at-spi-bus-laun-+-{dconf worker}&#xA;        |                 |-{gdbus}&#xA;        |                 `-{gmain}&#xA;...&#xA;    nice -n 10 long-running-command &amp;&#xA;    renice 20 2984&#xA;    renice 15 -u mike # changing  niceness for all process of mike user&#xA;    kill -9 PID&#xA;&#xA;shell&#xA;dgplug&#xA;ilugc&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>Today go through the commands to monitor processes and how to handle them</p>
<ul><li>ps – It reports the snapshot of the current process</li>
<li>init- It the parent process of all the processes.</li>
<li>pstree – Same as <em>ps</em> but list the process in form of tree with more details.</li>
<li>top- List down all the process running, update the snapshot after a while.</li>
<li>Kill – it signals the process
<ul><li>INT – 2 -Interrupt, stop running</li>
<li>TERM – 15 – ask a process to exit gracefully</li>
<li>KILL – 9 – force the process to stop running</li>
<li>TSTP – 18 – request the process to stop temporarily</li>
<li>HUP – 1 – Hang up</li></ul></li>
<li>nice – Every process run has priority and with nice we can control this priority, it ranges from +19(very nice) to -20(not very nice) decreased niceness higher the priority</li>
<li>renice- change the priority of the existing process</li></ul>

<pre><code class="language-bash">
&gt;&gt; top
PID  User  PR  NI  VIRT     RES     SHR     S  %CPU %MEM Time+ Command
3911 user  20   0 2855988 206872 141304 S  72.2  2.6   7:15.09 Web Content                                                                       
31980 user  20   0 3703988 509176 188188 S  33.3  6.3  49:36.10 firefox                                                                           
 2839 user  20   0 2834092 191744 128268 S  27.8  2.4  16:13.39 Web Content    

&gt;&gt;ps
  PID TTY          TIME CMD
 2418 pts/2    00:00:00 zsh
 4318 pts/2    00:00:00 ps

&gt;&gt; pstree | less
systemd-+-NetworkManager-+-dhclient
        |                |-dnsmasq---dnsmasq
        |                |-{gdbus}
        |                `-{gmain}
        |-accounts-daemon-+-{gdbus}
        |                 `-{gmain}
        |-acpid
        |-agetty
        |-apache2---2*[apache2---26*[{apache2}]]
        |-at-spi-bus-laun-+-{dconf worker}
        |                 |-{gdbus}
        |                 `-{gmain}
...
&gt;&gt; nice -n 10 long-running-command &amp;
&gt;&gt;renice 20 2984
&gt;&gt;renice 15 -u mike # changing  niceness for all process of mike user
&gt;&gt; kill -9 PID
</code></pre>

<p><a href="/sandeepk/tag:shell" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">shell</span></a>
<a href="/sandeepk/tag:dgplug" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">dgplug</span></a>
<a href="/sandeepk/tag:ilugc" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">ilugc</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/shell-day-5</guid>
      <pubDate>Mon, 13 Jul 2020 18:36:08 +0000</pubDate>
    </item>
    <item>
      <title>Shell: Day #4</title>
      <link>https://blogs.dgplug.org/sandeepk/shell-day-4</link>
      <description>&lt;![CDATA[Today was the day with the commands  grep and sed.&#xA;&#xA;grep - command used for the patter matching it have many useful options&#xA;    -i: to make case-insensitive search&#xA;    -r: search through the file in dire recursively&#xA;    - l: print the name of the file with matching string&#xA;    -c: print the counts of match&#xA;    -n: numbers the matching lines in the output&#xA;    -v: it&#39;s like not condition, print the reverse of the condition &#xA;&#xA;sed - its read the input lines, run script on them, and writes them to stdout. This command is good for the string replacement and editing of the files.&#xA;&#xA;Both these commands can be used with regex for the pattern matching.&#xA;&#xA;    grep -nv  ^# \| ^$  /etc/services |less&#xA;# will list all the lines from the file with do not start with # and ends with an empty line.&#xA;&#xA;    sed `s/UNIX/LINUX file.txt&#xA;&#xA;sed command will replace the occurrence of the UNIX word with the LINUX&#xA;&#xA;shellrun&#xA;dgplug&#xA;ilugc]]&gt;</description>
      <content:encoded><![CDATA[<p>Today was the day with the commands  <em>grep</em> and <em>sed</em>.</p>
<ul><li><p>grep – command used for the patter matching it have many useful options</p>
<ul><li>-i: to make case-insensitive search</li>
<li>-r: search through the file in dire recursively</li>
<li>– l: print the name of the file with matching string</li>
<li>-c: print the counts of match</li>
<li>-n: numbers the matching lines in the output</li>
<li>-v: it&#39;s like not condition, print the reverse of the condition</li></ul></li>

<li><p>sed – its read the input lines, run script on them, and writes them to stdout. This command is good for the string replacement and editing of the files.</p></li></ul>

<p>Both these commands can be used with regex for the pattern matching.</p>

<pre><code class="language-bash">
&gt;&gt; grep -nv  ^# \| ^$  /etc/services |less
# will list all the lines from the file with do not start with *#* and ends with an empty line.

&gt;&gt;sed ``s/UNIX/LINUX` file.txt

# sed command will replace the occurrence of the *UNIX* word with the *LINUX*
</code></pre>

<p><a href="/sandeepk/tag:shellrun" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">shellrun</span></a>
<a href="/sandeepk/tag:dgplug" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">dgplug</span></a>
<a href="/sandeepk/tag:ilugc" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">ilugc</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/shell-day-4</guid>
      <pubDate>Fri, 10 Jul 2020 18:21:57 +0000</pubDate>
    </item>
    <item>
      <title>Shell: Day #3</title>
      <link>https://blogs.dgplug.org/sandeepk/shell-day-3</link>
      <description>&lt;![CDATA[Today was the day of basic File Management,  Pipes, and Redirects.&#xA;So let&#39;s jump to the command&#39;s&#xA;&#xA;mkdir - create a directory for you, -p will create the parent directory if it does not exist.&#xA;rmdir - remove the empty directory&#xA;rm - remove the files and directory with -r.&#xA;pushd &amp; popd - this one is the new command I came across, it let you save the previous command and you can pop that command with popd when you require. Dirs let you list down the directories you can pop back too.&#xA;file - tells you about the format of the file&#xA;?,  -  these are the wildcards which help in pattern matching, &#39;&#39; for any number of character and whereas ? for only one character&#xA;| - called as pipe, it takes the output of one program and gives as an input to another program&#xA;Redirection (, ) -  this indicates to file to read input from,  this indicates the file to write output to.&#xA;    - Appends the output to the end of the file, If the file does not exist it creates a new one.&#xA;File Descriptors - Standard Input(0), Standard Output (1),  Standard Error (2), make sure to check the example below to see how you can use them&#xA;xargs- it read a text and pass them as input to the following command&#xA;tee - is a combination of   and |  and let you copy data from the input to the output or a file&#xA;&#xA;Now let see these commands in action &#xA;&#xA;    mkdir -p chess/pieces/board # create an directory for you.&#xA;    rmdir -p chess/pieces/board # will delete whole path if no other file or dir exist&#xA;    pushd /media/USB # will let you save this path&#xA;... # any command you run b/w&#xA;    popd # this will get you back to the pushed path&#xA;    dirs # list all the dir path saved&#xA;~/bash-trail ~ / ~/Code/tranzact ~/bash-trail/program&#xA;&#xA;    file shoppinglist &#xA;shoppinglist: ASCII text&#xA;&#xA;    whoami | rev # will reverse the output from the whoami output&#xA;keepdnas&#xA;&#xA;    last   last-login.txt # will save the output of login user to the file&#xA;&#xA;    wc &lt; last-login.txt # will pass the text from the file as input to the wc command&#xA;    program 2  file # will write the Standard error from the program to the file. File Descriptor&#xA;&#xA;    find /media/USB | xargs -l 3 rm -f  # this will pass files for USB dir and xargs will pass the 3 filenames at a time to remove them.&#xA;&#xA;    last | tee everyone.txt | grep bob   bob.txt&#xA;To save details of everyone’s logins and save Bob’s in files also.&#xA;&#xA; &#xA;shellrun&#xA;dgplug&#xA;ilugc]]&gt;</description>
      <content:encoded><![CDATA[<p>Today was the day of basic File Management,  Pipes, and Redirects.
So let&#39;s jump to the command&#39;s</p>
<ul><li>mkdir – create a directory for you, -p will create the parent directory if it does not exist.</li>
<li>rmdir – remove the empty directory</li>
<li>rm – remove the files and directory with <em>-r</em>.</li>
<li>pushd &amp; popd – this one is the new command I came across, it let you save the previous command and you can pop that command with <em>popd</em> when you require. <em>Dirs</em> let you list down the directories you can pop back too.</li>
<li>file – tells you about the format of the file</li>
<li>?, * –  these are the wildcards which help in pattern matching, &#39;*&#39; for any number of character and whereas <em>?</em> for only one character</li>
<li>| – called as pipe, it takes the output of one program and gives as an input to another program</li>
<li>Redirection (&lt;, &gt;) – &lt; this indicates to file to read input from, &gt; this indicates the file to write output to.</li>
<li>&gt;&gt; – Appends the output to the end of the file, If the file does not exist it creates a new one.</li>
<li>File Descriptors – Standard Input(0), Standard Output (1),  Standard Error (2), make sure to check the example below to see how you can use them</li>
<li>xargs- it read a text and pass them as input to the following command</li>
<li>tee – is a combination of <em>&gt;</em> and <em>|</em>  and let you copy data from the input to the output or a file</li></ul>

<p>Now let see these commands in action</p>

<pre><code class="language-bash">
&gt;&gt; mkdir -p chess/pieces/board # create an directory for you.
&gt;&gt; rmdir -p chess/pieces/board # will delete whole path if no other file or dir exist
&gt;&gt; pushd /media/USB # will let you save this path
... # any command you run b/w
&gt;&gt; popd # this will get you back to the pushed path
&gt;&gt; dirs # list all the dir path saved
~/bash-trail ~ / ~/Code/tranzact ~/bash-trail/program

&gt;&gt; file shopping_list 
shopping_list: ASCII text

&gt;&gt; whoami | rev # will reverse the output from the *whoami* output
keepdnas

&gt;&gt; last &gt; last-login.txt # will save the output of login user to the file

&gt;&gt; wc &lt; last-login.txt # will pass the text from the file as input to the *wc* command
&gt;&gt; program 2&gt; file # will write the Standard error from the program to the file. **File Descriptor**

&gt;&gt; find /media/USB | xargs -l 3 rm -f  # this will pass files for USB dir and xargs will pass the 3 filenames at a time to remove them.

&gt;&gt; last | tee everyone.txt | grep bob &gt; bob.txt
#  To save details of everyone’s logins and save Bob’s in files also.

</code></pre>

<p><a href="/sandeepk/tag:shellrun" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">shellrun</span></a>
<a href="/sandeepk/tag:dgplug" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">dgplug</span></a>
<a href="/sandeepk/tag:ilugc" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">ilugc</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/shell-day-3</guid>
      <pubDate>Thu, 09 Jul 2020 19:12:58 +0000</pubDate>
    </item>
    <item>
      <title>Shell: Day #2</title>
      <link>https://blogs.dgplug.org/sandeepk/shell-day-2</link>
      <description>&lt;![CDATA[Today run through the commands to process the Text streams from the shell.&#xA;&#xA;less - command let you show less content from the file you are viewing.&#xA;sort - helps you sort the output, -f let you do sort case-insensitive and -n numerical sort.&#xA;cut - help to select the fields(-f)/character(-c)&#xA;fmt - format the output of the file, you can specify the width with -w&#xA;tac - similar to the cat command but in reverse&#xA;sed- this command use to process each line of file with a script&#xA;&#xA;let see these command in action&#xA;&#xA;    less hello.txt&#xA;Hello World&#xA;THis is a text file&#xA;hello.txt (END)&#xA;&#xA;    cat shoppinglist &#xA;cucumber&#xA;bread&#xA;fish fingers&#xA;&#xA;    sort shoppinglist         &#xA;bread&#xA;cucumber&#xA;fish fingers&#xA;&#xA;    date&#xA;Thu Jul  9 00:21:17 IST 2020&#xA;&#xA;    date | cut -d &#34; &#34; -f1&#xA;Thu&#xA;&#xA;    cat COPYING |  less  &#xA;The GNU General Public License is a free, copyleft license for&#xA;software and other kinds of works.&#xA;&#xA;  The licenses for most software and other practical works are designed&#xA;&#xA;    cat COPYING |  less  | fmt -w 30&#xA;The GNU General Public&#xA;  License does not permit&#xA;  incorporating your program&#xA;&#xA;    cat copybump.py&#xA;! /usr/bin/env python3&#xA;&#xA;import datetime&#xA;import os&#xA;import re&#xA;import stat&#xA;import sys&#xA;...&#xA;if name == &#39;main&#39;:&#xA;    dowalk()&#xA;&#xA;    tac copybump.py&#xA;    dowalk()&#xA;if name == &#39;main&#39;:&#xA;...&#xA;import sys&#xA;import stat&#xA;import re&#xA;import os&#xA;import datetime&#xA;&#xA;! /usr/bin/env python3&#xA;&#xA;    sed -f spelling.sed  report.txt  corrected.txt # correct the spellling mistake in report.txt and output the correct text in corrected.txt&#xA;&#xA;shellrun&#xA;dgplug&#xA;ilugc]]&gt;</description>
      <content:encoded><![CDATA[<p>Today run through the commands to process the <em>Text streams</em> from the shell.</p>
<ul><li>less – command let you show <em>less</em> content from the file you are viewing.</li>
<li>sort – helps you sort the output, <em>-f</em> let you do sort <strong>case-insensitive</strong> and <em>-n</em> numerical sort.</li>
<li>cut – help to select the fields(<em>-f</em>)/character(<em>-c</em>)</li>
<li>fmt – format the output of the file, you can specify the width with <em>-w</em></li>
<li>tac – similar to the <em>cat</em> command but in reverse</li>
<li>sed- this command use to process each line of file with a script</li></ul>

<p>let see these command in action</p>

<pre><code class="language-bash">
&gt;&gt; less hello.txt
Hello World
THis is a text file
hello.txt (END)

&gt;&gt; cat shopping_list 
cucumber
bread
fish fingers

&gt;&gt; sort shopping_list         
bread
cucumber
fish fingers

&gt;&gt;date
Thu Jul  9 00:21:17 IST 2020

&gt;&gt;date | cut -d &#34; &#34; -f1
Thu

&gt;&gt;cat COPYING |  less  
The GNU General Public License is a free, copyleft license for
software and other kinds of works.

  The licenses for most software and other practical works are designed

&gt;&gt; cat COPYING |  less  | fmt -w 30
The GNU General Public
  License does not permit
  incorporating your program

&gt;&gt;cat copybump.py
#! /usr/bin/env python3

import datetime
import os
import re
import stat
import sys
...
if __name__ == &#39;__main__&#39;:
    do_walk()

&gt;&gt; tac copybump.py
    do_walk()
if __name__ == &#39;__main__&#39;:
...
import sys
import stat
import re
import os
import datetime

#! /usr/bin/env python3

&gt;&gt; sed -f spelling.sed &lt; report.txt &gt; corrected.txt # correct the spellling mistake in report.txt and output the correct text in corrected.txt
</code></pre>

<p><a href="/sandeepk/tag:shellrun" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">shellrun</span></a>
<a href="/sandeepk/tag:dgplug" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">dgplug</span></a>
<a href="/sandeepk/tag:ilugc" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">ilugc</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/shell-day-2</guid>
      <pubDate>Wed, 08 Jul 2020 18:59:44 +0000</pubDate>
    </item>
    <item>
      <title>Shell: Day #1</title>
      <link>https://blogs.dgplug.org/sandeepk/shell-day-1</link>
      <description>&lt;![CDATA[This post and the continuing post will be post/notes to share my journey of going through the shell to brush the commands which I forget and to learn some new ones.&#xA;&#xA;So here one or more things I learned today.&#xA;!! - will show you the previous command.&#xA;! String- show&#39;s the last command with the given string.&#xA;!$- will give the last argument of the previous command&#xA;!^ - will give you the first argument of the previous command&#xA;^String^replacement- will replace the first occurrence of the  String with the replacement string.&#xA;Ctrl + A - will get you to the start of the line.&#xA;Ctrl + E - will get you to the end of the line.&#xA;Ctrl + D - will delete the current character, even can close your shell session :).&#xA;For loop - yup we can write for loop to certain repetitive actions.&#xA;Locate - can help you to search for the file/s in the drive.&#xA;file – it not only help you with the file search just not based on the name but has many options to perform on the result and you can use regex for the file search also.&#xA;&#xA;Now let&#39;s dive into some cool example&#xA;&#xA;    ls&#xA;...&#xA;    clear&#xA;    !! # will refer to the previous command&#xA;    clear&#xA;    !l # refers to the previous command start with a given string in our case l&#xA;    ls&#xA;    cd Documents&#xA;    echo !$ # will refer to the Documents args from the previous command, same will be the case with !^  which refer the first args of the previous command&#xA;    ls&#xA;    echo !$&#xA;    echo ls&#xA;    echo Documents&#xA;    for file in *; echo ${file}; done # try to run this in the shell to see the output&#xA;  &#xA;References&#xA;http://www.linuxtraining.co.uk/download/newlinuxcourse_modules.pdf&#xA;http://tldp.org/LDP/Bash-Beginners-Guide/Bash-Beginners-Guide.pdf&#xA;&#xA;shellrun&#xA;dgplug&#xA;ilugc &#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>This post and the continuing post will be post/notes to share my journey of going through the shell to brush the commands which I forget and to learn some new ones.</p>

<p>So here one or more things I learned today.
*  !! – will show you the previous command.
*  ! String- show&#39;s the last command with the given string.
*  !$– will give the last argument of the previous command
*  !^ – will give you the first argument of the previous command
*  ^String^replacement- will replace the first occurrence of the * String* with the <em>replacement</em> string.
* Ctrl + A – will get you to the start of the line.
* Ctrl + E – will get you to the end of the line.
* Ctrl + D – will delete the current character, <em>even can close your shell session :)</em>.
* For loop – yup we can write for loop to certain repetitive actions.
* Locate – can help you to search for the file/s in the drive.
* file – it not only help you with the file search just not based on the name but has many options to perform on the result and you can use regex for the file search also.</p>

<p>Now let&#39;s dive into some cool example</p>

<pre><code class="language-bash">&gt;&gt; ls
...
&gt;&gt; clear
&gt;&gt;!! # will refer to the previous command
&gt;&gt; clear
&gt;&gt; !l # refers to the previous command start with a given string in our case `l`
&gt;&gt; ls
&gt;&gt; cd Documents
&gt;&gt; echo !$ # will refer to the *Documents* args from the previous command, same will be the case with *!^*  which refer the first args of the previous command
&gt;&gt; ls
&gt;&gt; echo !$
&gt;&gt; echo ls
&gt;&gt; echo Documents
&gt;&gt;for file in *; echo ${file}; done # try to run this in the shell to see the output
</code></pre>

<h2 id="references">References</h2>
<ul><li><a href="http://www.linuxtraining.co.uk/download/new_linux_course_modules.pdf" rel="nofollow">http://www.linuxtraining.co.uk/download/new_linux_course_modules.pdf</a></li>
<li><a href="http://tldp.org/LDP/Bash-Beginners-Guide/Bash-Beginners-Guide.pdf" rel="nofollow">http://tldp.org/LDP/Bash-Beginners-Guide/Bash-Beginners-Guide.pdf</a></li></ul>

<p><a href="/sandeepk/tag:shellrun" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">shellrun</span></a>
<a href="/sandeepk/tag:dgplug" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">dgplug</span></a>
<a href="/sandeepk/tag:ilugc" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">ilugc</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/shell-day-1</guid>
      <pubDate>Tue, 07 Jul 2020 17:59:38 +0000</pubDate>
    </item>
  </channel>
</rss>