<h1 id="upgsh-my-dumptxt-to-notemd">upg.sh my dump.txt to note.md</h1>
<p><strong>SYNOPSIS:</strong> <em>upg.sh</em></p>
<ul>
<li>Upgrade your system and store stdout into a markdown file.</li>
</ul>
<pre><code>#!/bin/bash
# upg.sh

FILENAME=sys-upgrade$(date +%m-%d-%Y).md
DIRECTORY=&quot;${HOME}/Documents/&quot;

# step 1: formatting.
echo -e &quot;# **System Upgrade:** $(date)\n&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;**Command:** \`sudo apt-get update; sudo apt-get upgrade --yes\`\n&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;**Command Breakdown:**&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;- \`sudo\`, Admin Privilages.&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;- \`apt-get\`, Package Manager.&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;- \`update;\`, Package Manager&#39;s task; update the system software repositories.&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;- \`sudo apt-get upgrade\`, Perform system upgrade with updated repositories.&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;- \`--yes\`, Answers yes to the prompt.&quot; \
    | tee -a ${DIRECTORY}${FILENAME}

# step 2: run commands with formatting.
echo -e &quot;\n**Command std-output:**\n&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;\`\`\`&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
    echo $(date) \
    | tee -a ${DIRECTORY}${FILENAME}

sudo apt-get update \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;\n# System update completed.\n&quot; \
    | tee -a ${DIRECTORY}${FILENAME}

sudo apt-get upgrade --yes \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;\n# System upgrade completed.\n&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;\`\`\`\n&quot; \
    | tee -a ${DIRECTORY}${FILENAME}

# step 3: additional details with more formatting.
echo -e &quot;**Upgraded Package Details:**\n&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;\`\`\`&quot; \
    | tee -a ${DIRECTORY}${FILENAME}

PKGLIST=$(sed -n &quot;/The following packages will be upgraded:/,/^.. upgraded/p&quot; ${FILENAME} \
    | sed &#39;1d;$d&#39; | xargs -n 1 | sed &#39;/:i386$/d&#39;) \

PKGCACHE=$(echo -e &quot;${PKGLIST}\n&quot; \
    | xargs -n1 -I _ apt-cache search _)
echo &quot;${PKGCACHE}&quot; &gt; ${DIRECTORY}delete.txt

echo &quot;${PKGLIST}&quot; \
    | xargs -n 1 -I _ echo &quot;sed -n &#39;/^_ /p&#39;&quot; &quot;${DIRECTORY}delete.txt&quot; \
    | bash | tee -a ${DIRECTORY}${FILENAME};

echo -e &quot;\`\`\`&quot; \
    | tee -a ${DIRECTORY}${FILENAME}

rm -v ${DIRECTORY}delete.txt;
PKGLIST=
PKGCACHE=

# step 4: place EOF (end of file).
    sed -i &#39;/EOF/d&#39; ${DIRECTORY}${FILENAME}
echo &quot;EOF&quot; &gt;&gt; ${DIRECTORY}${FILENAME}
#EOF
</code></pre>
<p><strong>Script breakdown:</strong> <em>upg.sh</em></p>
<ul>
<li><p>First, we declare bash as our shell with <code>#!/bin/bash</code>. We could also use <code>#!/bin/sh</code> for a more portable script.</p></li>
<li><p>I like to paste the name of the script we're working on into the script itself <code># upg.sh</code>.</p></li>
<li><p>Setup a couple of variables to shorten the syntax.</p></li>
</ul>
<pre><code>FILENAME=sys-upgrade$(date +%m-%d-%Y).md
DIRECTORY=&quot;${HOME}/Documents/&quot;
</code></pre>
<ul>
<li><code># step 1: formatting.</code>
<ul>
<li>Build labels and a short breakdown of the update/upgrade commands used.</li>
</ul></li>
</ul>
<pre><code>echo -e &quot;# **System Upgrade:** $(date)\n&quot; \                                                    &lt;-- formatting: label with date.
    | tee -a ${DIRECTORY}${FILENAME}                                                           &lt;-- path/to/file
echo -e &quot;**Command:** \`sudo apt-get update; sudo apt-get upgrade --yes\`\n&quot; \                 &lt;-- formatting: command label.
    | tee -a ${DIRECTORY}${FILENAME}                                                           &lt;-- path/to/file
echo -e &quot;**Command Breakdown:**&quot; \                                                             &lt;-- formatting: label.
    | tee -a ${DIRECTORY}${FILENAME}                                                           &lt;-- path/to/file
echo -e &quot;- \`sudo\`, Admin Privilages.&quot; \                                                      &lt;-- formatting: label.
    | tee -a ${DIRECTORY}${FILENAME}                                                           &lt;-- path/to/file
echo -e &quot;- \`apt-get\`, Package Manager.&quot; \                                                    &lt;-- formatting: label.
    | tee -a ${DIRECTORY}${FILENAME}                                                           &lt;-- path/to/file
echo -e &quot;- \`update;\`, Package Manager&#39;s task; update the system software repositories.&quot; \    &lt;-- formatting: label.
    | tee -a ${DIRECTORY}${FILENAME}                                                           &lt;-- path/to/file
echo -e &quot;- \`sudo apt-get upgrade\`, Perform system upgrade with updated repositories.&quot; \      &lt;-- formatting: label.
    | tee -a ${DIRECTORY}${FILENAME}                                                           &lt;-- path/to/file
echo -e &quot;- \`--yes\`, Answers yes to the prompt.&quot; \                                            &lt;-- formatting: label.
    | tee -a ${DIRECTORY}${FILENAME}                                                           &lt;-- path/to/file
</code></pre>
<ul>
<li><code># step 2: run commands with formatting.</code>,
<ul>
<li>Setup labels and an area for the stdout to be store with markdown formatting.</li>
<li>We place the time and date into the stdout area then run the commands.</li>
</ul></li>
</ul>
<pre><code>echo -e &quot;\n**Command std-output:**\n&quot; \                                                        &lt;-- formatting: label.
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;\`\`\`&quot; \                                                                             &lt;-- formatting: markdown.
    | tee -a ${DIRECTORY}${FILENAME}
    echo $(date) \                                                                             &lt;-- command: date.
    | tee -a ${DIRECTORY}${FILENAME}

sudo apt-get update \                                                                          &lt;-- command: update.
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;\n# System update completed.\n&quot; \                                                     &lt;-- formatting: label.
    | tee -a ${DIRECTORY}${FILENAME}

sudo apt-get upgrade --yes \                                                                   &lt;-- command: upgrade with &quot;--yes&quot; option.
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;\n# System upgrade completed.\n&quot; \                                                    &lt;-- formatting: label.
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;\`\`\`\n&quot; \                                                                           &lt;-- formatting: markdown.
    | tee -a ${DIRECTORY}${FILENAME}
</code></pre>
<ul>
<li><code># step 3: additional details with more formatting.</code>,
<ul>
<li>List the packages that were upgraded with details from system cache.</li>
</ul></li>
</ul>
<pre><code>echo -e &quot;**Upgraded Package Details:**\n&quot; \                                                    &lt;-- formatting: label.
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;\`\`\`&quot; \                                                                             &lt;-- formatting: markdown.
    | tee -a ${DIRECTORY}${FILENAME}

PKGLIST=$(sed -n &quot;/The following packages will be upgraded:/,/^.. upgraded/p&quot; ${DIRECTORY}${FILENAME} \  &lt;--| variable with list of packages within it.
    | sed &#39;1d;$d&#39; | xargs -n 1 | sed &#39;/:i386$/d&#39;) \                                            &lt;--| sed: filter the first and last lines then remove the :i386 duplicate packages.

PKGCACHE=$(echo -e &quot;${PKGLIST}\n&quot; \                                                            &lt;--| variable with massive apt-cache search results.
    | xargs -n1 -I _ apt-cache search _)                                                       &lt;--| xargs runs the PKGLIST (the _ is the value of PKGLIST) into the apt-cache search.
echo &quot;${PKGCACHE}&quot; &gt; ${DIRECTORY}delete.txt                                                    &lt;--| I had to put the PKGCACHE in a file. I couldn&#39;t get sed to filter a variable (yet).

echo &quot;${PKGLIST}&quot; \                                                                            &lt;--| use that PKGLIST to create a few sed commands to filter the file called &quot;delete.txt&quot;.
    | xargs -n 1 -I _ echo &quot;sed -n &#39;/^_ /p&#39;&quot; &quot;${DIRECTORY}delete.txt&quot; \                        ^--| xargs is used to create the sed commands.
    | bash | tee -a ${DIRECTORY}${FILENAME};                                                   &lt;--| run the sed commands through bash then store them.

echo -e &quot;\`\`\`&quot; \
    | tee -a ${DIRECTORY}${FILENAME}

rm -v ${DIRECTORY}delete.txt;                                                                  &lt;--| use rm to delete the file called &quot;delete.txt&quot; it has the apt-cache search results in it.
PKGLIST=                                                                                       &lt;--| empty the variable. why? why not!
PKGCACHE=                                                                                      &lt;--| empty the variable. why? why not!
</code></pre>
<ul>
<li><code># step 4: place EOF (end of file).</code>,
<ul>
<li>Add EOF (END OF FILE) to the end of the file. If one is already there, -</li>
<li>it's removed then replaced in the correct position.</li>
</ul></li>
</ul>
<pre><code>    sed -i &#39;/EOF/d&#39; ${DIRECTORY}${FILENAME}                                                    &lt;--| search for EOF then remove it. we don&#39;t want multiple EOF if we run the script multiple times in the same day.
echo &quot;EOF&quot; &gt;&gt; ${DIRECTORY}${FILENAME}                                                          ^--| adds the EOF (End Of File) at the end of the file.  I read it was a nice thing to do.
#EOF                                                                                           &lt;--| Yep. it&#39;s there.

</code></pre>
<hr />
<p><strong>SYNOPSIS:</strong> <em>note.sh</em> "command" "filename"</p>
<ul>
<li>example: note.sh "ls -lhA" "basic-list"</li>
<li>make markdown notes of your commands.</li>
</ul>
<pre><code>#!/bin/bash
# note.sh &quot;command&quot; &quot;filename&quot; no extentions.

# variables
FILENAME=$2$(date +%m-%d-%Y).md
DIRECTORY=&quot;${HOME}/Documents/&quot;

# step 1: create file with formatting.
echo -e &quot;# **Command:** \` $1 \`\n&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;**Command Breakdown:**&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo &quot;$1&quot; | tr &quot; &quot; &#39;\n&#39; \
    | awk &#39;{ print &quot;- `&quot; $0 &quot;`, info.&quot; }&#39; \
    | tee -a ${DIRECTORY}${FILENAME}

# step 2: run command with more formatting.
echo -e &quot;\n**Command std-output:**&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;\`\`\`\n$(date)&quot; \
    | tee -a ${DIRECTORY}${FILENAME}

echo $1 | bash \
    | tee -a ${DIRECTORY}${FILENAME}

echo -e &quot;\`\`\`&quot; \
    | tee -a ${DIRECTORY}${FILENAME}

echo -ne &quot;\n${FILENAME} has been updated $(date).&quot;

# step 3: insert EOF (End Of File).
sed -i &#39;/EOF/d&#39; ${DIRECTORY}${FILENAME}
echo EOF &gt;&gt; ${DIRECTORY}${FILENAME}
</code></pre>
<p><strong>Script breakdown:</strong> <em>upg.sh</em></p>
<ul>
<li><p>First, we declare bash as our shell with <code>#!/bin/bash</code>. We could also use <code>#!/bin/sh</code> for a more portable script.</p></li>
<li><p>I like to paste the name of the script we're working on into the script itself <code># upg.sh</code>.</p></li>
<li><p>Setup a couple of variables to shorten the syntax.</p></li>
</ul>
<pre><code>FILENAME=$2$(date +%m-%d-%Y).md                                                                &lt;--| the &quot;$2&quot; is the second user input (file name) from the commandline.
DIRECTORY=&quot;${HOME}/Documents/&quot;
</code></pre>
<ul>
<li><code># step 1: create file with formatting.</code>
<ul>
<li>Build labels for Command Name with a short breakdown of the command(s) used.</li>
<li><strong>Note:</strong> the breakdown must be entered manually.</li>
</ul></li>
</ul>
<pre><code>echo -e &quot;# **Command:** \` $1 \`\n&quot; \                                                          &lt;--| the &quot;$1&quot; is the first user input (the command) from the commandline.
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;**Command Breakdown:**&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo &quot;$1&quot; | tr &quot; &quot; &#39;\n&#39; \                                                                      &lt;--| This just breaks the command into parts then adds some markdown formatting for use to add -
    | awk &#39;{ print &quot;- `&quot; $0 &quot;`, info.&quot; }&#39; \                                                    ^--| details to later. I just added the word info so you know to provide info about the command. -
    | tee -a ${DIRECTORY}${FILENAME}                                                           ^--| the formatting gets a bit crazy if you use something like: awk {&#39; print $1 $2 $3 &#39;} path/to/file;  each space becomes a newline with the markdown formatting.
</code></pre>
<ul>
<li><code># step 2: run command with more formatting.</code>
<ul>
<li>Echo the Command into <em>bash</em> with markdown formatting for stdout.</li>
</ul></li>
</ul>
<pre><code>echo -e &quot;\n**Command std-output:**&quot; \
    | tee -a ${DIRECTORY}${FILENAME}
echo -e &quot;\`\`\`\n$(date)&quot; \
    | tee -a ${DIRECTORY}${FILENAME}

echo $1 | bash \
    | tee -a ${DIRECTORY}${FILENAME}

echo -e &quot;\`\`\`&quot; \
    | tee -a ${DIRECTORY}${FILENAME}

echo -ne &quot;\n${FILENAME} has been updated $(date).&quot;
</code></pre>
<ul>
<li><code># step 3: insert EOF (End Of File).</code>
<ul>
<li>Add EOF (END OF FILE) to the end of the file. If one is already there, -</li>
<li>it's removed then replaced in the correct position.</li>
</ul></li>
</ul>
<pre><code>sed -i &#39;/EOF/d&#39; ${DIRECTORY}${FILENAME}
echo EOF &gt;&gt; ${DIRECTORY}${FILENAME}
</code></pre>
<hr />
<p><strong>Correspondent:</strong> <a href="https://hackerpublicradio.org/correspondents/0391.html">Some Guy On The Internet.</a><br />
<strong>Host ID:</strong> 391<br />
<strong>E-mail:</strong> <a href="/tmp/.mount_Joplin1UDfeV/resources/app.asar/Lyunpaw@gmail.com" title="Lyunpaw@gmail.com">Lyunpaw.nospam@nospam.gmail.com</a></p>
<ul>
<li>use <strong>"hpr391"</strong> as the subject line for all emails to avoid the junk filter.</li>
<li><a href="https://drive.google.com/file/d/1vaGWVv48IcPNXXBknDer8ZBsUvix6qp4/view?usp=sharing">show notes markdown file</a> <a href="https://creativecommons.org/licenses/by-sa/4.0/"><img src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" alt="Creative Commons License" /></a> This work is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.</li>
</ul>
