<?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: Nitin Namdev</title>
    <description>The latest articles on DEV Community by Nitin Namdev (@vortexdude).</description>
    <link>https://dev.to/vortexdude</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%2F506471%2F4ac8b82e-3247-48ed-a5f8-40fddc238c47.png</url>
      <title>DEV Community: Nitin Namdev</title>
      <link>https://dev.to/vortexdude</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vortexdude"/>
    <language>en</language>
    <item>
      <title>Redirect shell command output</title>
      <dc:creator>Nitin Namdev</dc:creator>
      <pubDate>Tue, 16 May 2023 09:11:36 +0000</pubDate>
      <link>https://dev.to/vortexdude/redirect-shell-command-output-2jh8</link>
      <guid>https://dev.to/vortexdude/redirect-shell-command-output-2jh8</guid>
      <description>&lt;p&gt;Shell scripts provide a very powerful feature: the ability to redirect the output from commands and scripts and send it to files, devices, or even as input to other commands or scripts.&lt;/p&gt;

&lt;p&gt;Types of output&lt;br&gt;
Commands and scripts in a shell can generate two basic types of outputs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;STDOUT: The normal output from a command/script (file descriptor 1)&lt;/li&gt;
&lt;li&gt;STDERR: The error output from a command/script (file descriptor 2)
By default, STDOUT and STDERR are sent to your terminal's screen.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Redirect STDOUT
&lt;/h2&gt;

&lt;p&gt;For the following examples, I will use this simple set of files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ls -la file*
-rw-r--r--. 1 admin2 admin2  7 Mar 27 15:34 file1.txt
-rw-r--r--. 1 admin2 admin2 10 Mar 27 15:34 file2.txt
-rw-r--r--. 1 admin2 admin2 13 Mar 27 15:34 file3.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm running a simple ls commands to illustrate STDOUT vs. STDERR, but the same principle applies to most of the commands you execute from a shell.&lt;/p&gt;

&lt;p&gt;I can redirect the standard output to a file using ls file* &amp;gt; my_stdout.txt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ls file* &amp;gt; my_stdout.txt

$ cat my_stdout.txt 
file1.txt
file2.txt
file3.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, I run a similar command, but with a 1 before &amp;gt;. Redirecting using the &amp;gt; signal is the same as using 1&amp;gt; to do so: I'm telling the shell to redirect the STDOUT to that file. If I omit the file descriptor, STDOUT is used by default. I can prove this by running the sdiff command to show the output of both commands side by side:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ls file* 1&amp;gt; my_other_stdout.txt

$sdiff my_stdout.txt my_other_stdout.txt
file1.txt                        file1.txt
file2.txt                        file2.txt
file3.txt                        file3.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Send STDOUT and STDERR to the same file
&lt;/h2&gt;

&lt;p&gt;Another common situation is to send both STDOUT and STDERR to the same file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ls file* non-existing-file* &amp;gt; my_consolidated_output.txt 2&amp;gt;&amp;amp;1

$ cat my_consolidated_output.txt 
ls: cannot access 'non-existing-file*': No such file or directory
file1.txt
file2.txt
file3.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, all output (normal and error) is sent to the same file.&lt;/p&gt;

&lt;p&gt;The 2&amp;gt;&amp;amp;1 construction means "send the &lt;strong&gt;STDERR&lt;/strong&gt; to the same place you are sending the &lt;strong&gt;STDOUT&lt;/strong&gt;."&lt;/p&gt;

</description>
      <category>linux</category>
      <category>bash</category>
      <category>shell</category>
    </item>
    <item>
      <title>Ansible Sandbox for Developing Custom Module</title>
      <dc:creator>Nitin Namdev</dc:creator>
      <pubDate>Mon, 15 May 2023 17:47:34 +0000</pubDate>
      <link>https://dev.to/vortexdude/ansible-sandbox-for-developing-custom-module-5925</link>
      <guid>https://dev.to/vortexdude/ansible-sandbox-for-developing-custom-module-5925</guid>
      <description>&lt;p&gt;Hello all,&lt;/p&gt;

&lt;p&gt;Today ansible is the most popular tool in the automation part, so for creating playbook, roles and modules you need to do too much manual work, for getting rid from this I have created a script that will create a ansible role structure with tasks, handlers, deafults, template and library&lt;/p&gt;

&lt;p&gt;And also I created a hello custom module that is called in the task so you can work without any manual work, you can directly run the command and you will have ready to go ansible environment.&lt;/p&gt;

&lt;p&gt;Simply run the following command —&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /opt/
wget -O - https://raw.githubusercontent.com/vortexdude/src/main/script.sh | bash -s newrole
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running the above command in your linux you need the package of &lt;strong&gt;ansible&lt;/strong&gt; and &lt;strong&gt;wget&lt;/strong&gt; and &lt;strong&gt;git&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;to run the ansible playbook —&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ansible-playbook ansible/main.yml 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;also it will create the inventory file where you can define you all of the servers the path of the inventory will be inventory/all.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;hello.py&lt;/strong&gt; is your custom module and the file wll be in the following location&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vi ansible/roles/newrole/library/hello.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ansible</category>
      <category>linux</category>
      <category>python</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
