Categories
Tech

How to auto-update CNote, Simple CLI Note Taking Application, to Google Drive Cloud

Super simple command line note taking tool for tracking breadcrumb trail during application development…
CNote is a super-simple command line based Note taking application which we use to track changes, take notes before signing-off etc. during development. It can be used on all variants of Unix, Linux and Mac OS. It’s power lies in quickly taking notes as you are working, without interrupting your flow. The notes are searchable and stored in a viewable text file. You can download it from CNote – CLI Note Taking Application site or directly install it from command line with the following:

wget --no-check-certificate -q -O- https://raw.githubusercontent.com/angsuman/cnote/master/install.sh|bash -

CNotes is super-fast because it stores the notes locally, specifically in ~/.notes.
As we started piling up valuable notes you may start thinking what-if you machine crashes?
One simple solution is to create a symbolic link to it from DropBox managed folder. This ensures DropBox updates it in their cloud whenever new notes are added.
DropBox Nazi says: No DropBox for you!
Incidentally I use CentOS 5.1.x (latest update) on Desktop, which is not supported by DropBox. I also use Raspberry Pi, which also is not supported by DropBox.
Enter Google Drive to the rescue
I tried to make DropBox command line tool work but I found out that DropBox command line client will not work without full installation. This is not possible as CentOS 5.1.x and RaspBerry Pi are unsupported platforms.
Google Drive has a nice third-party command line tool called gdrive (download link) which is just right for my purpose. So instead of wasting more time trying to make DropBox work on RaspberryPi etc., I decided to use Google Drive cloud for backup. I used an unused Google Account for this purpose.
Get access to Google Drive

    • Open a browser and login to Google with the account you want to use.
      • Note: This may be done later too.
    • Upload ~/.notes to Google Drive for the first time:
      gdrive upload ~/.notes
      • This will provide an url which you have to open in your browser to allow gdrive to access files and directories in your Google Drive. After allowing you will be given a code which you will have to copy-paste in command line for the first upload to complete
      • After upload it prints a string (something like: 0B8qjyN8TMP9zSmRYQzhNTaBcdEFg) which is the ID of the file. Copy it. This magic key is the identity of your file on Google Drive.

Backup CNote in Google Drive

    • Now create a file named (for example) updateNoteonGDrive and open it in a text editor and paste the saved file ID.
      nohup ~/bin/gdrive update 0B8qjySampleIDQzhNTaBcdEFg ~/.notes >/dev/null 2>&1 &
  • Make this file executable with chmod:
    chmod 700 ~/bin/updateNoteonGDrive
  • Run it by hand to ensure that it properly updates your notes file in Google Drive.
  • Now open ~/.bashrc with a text editor and invoke this after saving your note like:
    n() {
            echo `date "+%Y-%m-%d %H:%M:%S"`'> '"$*" >> ~/.notes
            tail -1 ~/.notes
            updateNoteonGDrive
    }
  • This ensures every note is backed up in Google Drive. The backup process runs in the background so press Enter and continue with your work. Even if it fails because Internet is down, it will update when you write the next note.

Questions:

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.