<?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>Forem: Kapildev Neupane</title>
    <description>The latest articles on Forem by Kapildev Neupane (@kpldvnpne).</description>
    <link>https://forem.com/kpldvnpne</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%2F146398%2Fd3644592-35e1-4685-b0ab-b705673cdf00.png</url>
      <title>Forem: Kapildev Neupane</title>
      <link>https://forem.com/kpldvnpne</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kpldvnpne"/>
    <language>en</language>
    <item>
      <title>How to enable DEBUG logs in Flyway?</title>
      <dc:creator>Kapildev Neupane</dc:creator>
      <pubDate>Sun, 12 May 2024 04:28:09 +0000</pubDate>
      <link>https://forem.com/kpldvnpne/how-to-enable-debug-logs-in-flyway-2b0g</link>
      <guid>https://forem.com/kpldvnpne/how-to-enable-debug-logs-in-flyway-2b0g</guid>
      <description>&lt;ol&gt;
&lt;li&gt;Enable all DEBUG logs created by &lt;code&gt;org.flywaydb&lt;/code&gt;
Your SQL and Java-based migrations are all run by code inside &lt;code&gt;org.flywaydb&lt;/code&gt;. Hence, if you want to debug what's wrong with your SQL/Java-based migrations, you can enable logging in &lt;code&gt;org.flywaydb&lt;/code&gt; by including the following in your profile's &lt;code&gt;application.yml&lt;/code&gt; file.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;logging:
  level:
    org:
      flywaydb: DEBUG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Enable all DEBUG logs created by your Java-based migrations
If you have Java-based migration in your repository, and want to debug it, enable debug logs by including this in your profile's &lt;code&gt;application.yml&lt;/code&gt; file:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;logging:
  level:
    db:
      migration: DEBUG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE: You need to have them placed in &lt;code&gt;src/main/db/migration&lt;/code&gt; for this to work.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to reduce space usage in Google Drive without actually removing the files</title>
      <dc:creator>Kapildev Neupane</dc:creator>
      <pubDate>Mon, 18 Mar 2024 07:30:19 +0000</pubDate>
      <link>https://forem.com/kpldvnpne/how-to-reduce-space-usage-in-google-drive-without-actually-removing-the-files-2l6m</link>
      <guid>https://forem.com/kpldvnpne/how-to-reduce-space-usage-in-google-drive-without-actually-removing-the-files-2l6m</guid>
      <description>&lt;p&gt;If you are like me, you have probably stored up your photos and videos in your Google Drive. When that happens, you use up your 16 GBs of free space provided by Google. And if you are anything like me, you probably don't want to pay money to save up some space. If so, follow the instructions below to reduce your space usage without deleting your files off the cloud.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftmajawiqlyus0vmq2tn8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftmajawiqlyus0vmq2tn8.png" alt="Image description" width="800" height="72"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new Google Drive account. You don't need to worry about providing new mobile number -- same number you have used in your another account would work.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1xn3w9tu97ac9cr17api.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1xn3w9tu97ac9cr17api.png" alt="Image description" width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Move over some of your big files to this account by doing the following:
i. First, share the files with the other account by right clicking the file/folder, then hover to share and click on &lt;strong&gt;Share&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc7p58dhbihwsdarm3ilv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc7p58dhbihwsdarm3ilv.png" alt="Image description" width="800" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ii. In the Input box, enter the other email address and then click on "Send".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1cuzok26aq1ce0to4t4l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1cuzok26aq1ce0to4t4l.png" alt="Image description" width="800" height="634"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iii. Then, go again to the share dialog by right clicking the file/folder, then hover to share and click on "Share". In the dialog box, click on the role beside the other email and select "Transfer Ownership".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdidtvpuwpi3ujhry924u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdidtvpuwpi3ujhry924u.png" alt="Image description" width="640" height="664"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iv. Then, open the Gmail from the other account and wait for the email. Once the email arrives, accept the transfer of ownership.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpgl5vii8jtnjks1irmwi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpgl5vii8jtnjks1irmwi.png" alt="Image description" width="800" height="775"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Lastly, add the shortcut to the files in your old account. Follow the following instructions to do that:
i. First, go to "Shared with me".&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F848xjlfqa6eiku75pd82.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F848xjlfqa6eiku75pd82.png" alt="Image description" width="476" height="80"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ii. Find the file/folder that you transferred to the new account.&lt;br&gt;
  iii. Right click the item and on "Organize", select "Add shortcut".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9lat3qbvqucf31knnyov.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9lat3qbvqucf31knnyov.png" alt="Image description" width="800" height="558"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iv. Add the shortcut to where the file/folder was initially for your own convenience.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ketlf3gim350n7zbrve.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ketlf3gim350n7zbrve.png" alt="Image description" width="800" height="669"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading this article. If you found this article useful, please let me know by liking this article and commenting below. &lt;/p&gt;

</description>
      <category>gdrive</category>
      <category>google</category>
      <category>drive</category>
      <category>save</category>
    </item>
    <item>
      <title>How to auto shutdown when you are not using the Cloud Virtual Machines?</title>
      <dc:creator>Kapildev Neupane</dc:creator>
      <pubDate>Sun, 31 Oct 2021 06:12:13 +0000</pubDate>
      <link>https://forem.com/kpldvnpne/how-to-auto-shutdown-when-you-are-not-using-the-ec2-instance-5g5e</link>
      <guid>https://forem.com/kpldvnpne/how-to-auto-shutdown-when-you-are-not-using-the-ec2-instance-5g5e</guid>
      <description>&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;I always forget to turn off my virtual machines on Cloud when I am not using the computer. Because of this, I always end up paying tons for forgetting to turn it off. The cost of these instances/machines are usually $1 per hour. Hence, if I forget to turn it off for a whole day, I would incur $24.&lt;/p&gt;

&lt;p&gt;This feels like something the machine should do itself and not burden me for remembering. Hence, I have gathered information from all over the web to make this short, simple and easy to follow guide.&lt;/p&gt;

&lt;h2&gt;
  
  
  A script that checks if there is a user connecting through SSH
&lt;/h2&gt;

&lt;p&gt;First, we need a script that checks if there is a user connecting through SSH and turn off the EC2 instance if there are none for a set interval of time. The following script does exactly that:&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;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="c"&gt;# Reference: https://serverfault.com/a/1061792&lt;/span&gt;
&lt;span class="c"&gt;# Shuts down the host on inactivity.&lt;/span&gt;
&lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="c"&gt;# Designed to be executed as root from a cron job.&lt;/span&gt;
&lt;span class="c"&gt;# It will power off on the 2nd consecutive run without an active ssh session.&lt;/span&gt;
&lt;span class="c"&gt;# That prevents an undesirable shutdown when the machine was just started, or on a brief disconnect.&lt;/span&gt;
&lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="c"&gt;# To enable, add this entry to /etc/crontab:&lt;/span&gt;
&lt;span class="c"&gt;# */5 *   * * *   root    /home/&amp;lt;name_of_user&amp;gt;/dotfiles/bin/shutdown-if-inactive&lt;/span&gt;
&lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; nounset &lt;span class="nt"&gt;-o&lt;/span&gt; errexit &lt;span class="nt"&gt;-o&lt;/span&gt; pipefail

&lt;span class="nv"&gt;MARKER_FILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/tmp/ssh-inactivity-flag"&lt;/span&gt;

&lt;span class="nv"&gt;STATUS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;netstat | &lt;span class="nb"&gt;grep &lt;/span&gt;ssh | &lt;span class="nb"&gt;grep &lt;/span&gt;ESTABLISHED &amp;amp;&amp;gt;/dev/null &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo &lt;/span&gt;active &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;echo &lt;/span&gt;inactive&lt;span class="si"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$STATUS&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"inactive"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
  if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$MARKER_FILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Powering off due to ssh inactivity."&lt;/span&gt;
    &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$MARKER_FILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    /sbin/shutdown &lt;span class="nt"&gt;-h&lt;/span&gt; now
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="c"&gt;# Create a marker file so that it will shut down if still inactive on the next time this script runs.&lt;/span&gt;
    &lt;span class="nb"&gt;touch&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$MARKER_FILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;fi
else&lt;/span&gt;
  &lt;span class="c"&gt;# Delete marker file if it exists&lt;/span&gt;
  &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;--force&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$MARKER_FILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Save this script in a file named: &lt;code&gt;~/bin/shutdown-if-inactive.sh&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Don't forget to make the file executable:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x ~/bin/shutdown-if-inactive.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add the script to a cron job to run it every 10 minutes
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open up the crontab config file for the root user:
&lt;/li&gt;
&lt;/ol&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;crontab  &lt;span class="nt"&gt;-u&lt;/span&gt; root &lt;span class="nt"&gt;-e&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: we need to run this cronjob as a root because shutting down requires elevated privileges.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add the following line to the end of the file so that the script from above is invoked every 10 minutes:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*/10 * * * * /home/&amp;lt;name_of_user&amp;gt;/bin/shutdown-if-inactive.sh &amp;gt;&amp;gt; /home/&amp;lt;name_of_user&amp;gt;/bin/shutdown-if-inactive-logs  2&amp;gt;&amp;amp;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;br&gt;
a. &lt;code&gt;*/10 * * * *&lt;/code&gt; means run the script every 10 minutes at any hour, at any day, at any month and at any day of the month respectively. &lt;br&gt;
b. &lt;code&gt;/home/&amp;lt;name_of_user&amp;gt;/bin/shutdown-if-inactive.sh&lt;/code&gt; is the file where we put the bash script from above. &lt;br&gt;
c. &lt;code&gt;/home/&amp;lt;name_of_user&amp;gt;/bin/shutdown-if-inactive-logs&lt;/code&gt; is the file where we put the output and errors from the script.&lt;br&gt;
d. &lt;code&gt;2&amp;gt;&amp;amp;1&lt;/code&gt; means redirect &lt;code&gt;stderr&lt;/code&gt; to &lt;code&gt;stdout&lt;/code&gt;. Basically, it means, we are redirecting error stream the output stream. Combine it with &lt;code&gt;&amp;gt;&amp;gt; file_here&lt;/code&gt;; and we get errors appended to the file.&lt;br&gt;
e. Here, we are storing logs to be able to debug why the above script is not working properly.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I would recommend changing the above line to have &lt;code&gt;*/1&lt;/code&gt; instead of &lt;code&gt;*/10&lt;/code&gt;. This way, you can check if this whole thing works in 2 minutes instead of having to wait for the whole 20 minutes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Please let me know in the comments if this worked for you. Thank you for reading my first post in DEV.to.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>linux</category>
      <category>gcp</category>
      <category>azure</category>
    </item>
  </channel>
</rss>
