Showing posts with label utilities. Show all posts
Showing posts with label utilities. Show all posts

January 3, 2016

chequePrint : Linux utility to print into cheques

The problem : As I do not write much on paper these days, writing cheques will cause some cheque leaves go waste. Earlier I had created a template in LibreOffice to solve the problem. However, I could not use that template as it was for a different bank. It was too difficult to get the alignment correct as there were boxes for days, month & year.

Solution : Write a script! Initially considered generating TeX files but zeroed in on PostScript as it would be easy to do the layout.
The script is available in the chequePrint GitHub repo.

August 9, 2015

syncReaders: Linux utility to synchronize Calibre & CoolReader database

I use the coolReader in my Android phone and tablet to read e-books. The e-books are managed in my Linux system using Calibre. One of the problem I had was that it was difficult to maintain the ratings and read status of the books across the three devices. Manually updating the ratings and read status was not practical. Since I go by "Machines should work and men should enjoy", some time ago I ventured into writing a program to synchronize the status and read status in both applications. I have been using the utility for a while and serves my purpose. The downside is that the database files of the applications have to be manually copied to Linux system for synchronization and then copy back to respective devices manually.

The source code for syncReaders is available here : https://github.com/primejyothi/syncReaders

August 17, 2014

Up!

Like many other scripts, the bash shell function "up" is a by product of my laziness. As the name vaguely indicates, it can move you up in the directory tree. If you want to move 3 levels up in the directory tree, you invoke the function as up 3 instead of cd ../../../  which saves a ton of typing. The shell function can be downloaded from my GitHub repo. 

# Go n level up in the directory structure.
# License : GPLv3
function up ()
{
        lvls=""
        if [[ ! -z "$1" ]]
        then
                for i in `seq $1`
                do
                        lvls="${lvls}../"
                done
        else
                lvls="../"
        fi

        # Will land up in / if n is too large.
        cd ${lvls}
        pwd
}


The ShellUtils repo contains few other shell scripts that might be interesting. See the Readme file in the repo to find out what those scripts are doing.

March 25, 2014

ഗാലിഫൈ

പ്രോഗ്രാം കോർഡമ്പ് ചെയ്തോ? കമ്പൈലർ എണ്ണമില്ലാത്ത എററുകൾ തരുന്നോ? ലവൻ നിങ്ങളുടെ കോഡ് കൊളമാക്കിയോ? ഇത്തരം സന്ദർഭങ്ങളിലുപയോഗിക്കാൻ പറ്റിയ തെറികളുണ്ടോ നിങ്ങളുടെ പക്കൽ? ഇല്ലെങ്കിൽ ഇതാ ഗാലിഫൈ സ്ക്രിപ്റ്റ്. പതിനഞ്ച് ഹൈക്വാളിറ്റി ബിൽറ്റിൻ തെറികളുമായി ഗാലിഫൈ സ്ക്രിപ്റ്റ് ഡൗൺലോഡൂ : http://goo.gl/cVKglH
ബിൽറ്റിൻ എന്റ്രികൾ പോര എങ്കിൽ കസ്റ്റം എന്റ്രികൾ ~/.galify.rc എന്ന ഫയലിൽ ചേർക്കാവുന്നതാണ്

ഈ സ്കിപ്റ്റ് എഴുതാനുള്ള പ്രചോദനം സുബിൻ ഡയസ്പോറയിൽ ഇട്ട ഈ പോസ്റ്റാണ് : https://poddery.com/posts/1033614

February 24, 2014

JOSM Tile stitching script

I wrote a Linux shell utility to combine the OpenStreetMap map tiles downloaded by JOSM into a single big image. The script is available here : https://github.com/primejyothi/jMapStitch

January 29, 2014

Standardizing glyph names in Unicode fonts

On New year's eve, Rajeesh K Nambiar  conducted a nice font training session. During the session he mentioned that the glyph names in different Malayalam Unicode fonts maintained by SMC are not standardized and this is causing a bit of problems in the maintenance of different fonts.

Here is a small utility I have developed that will help in renaming the glyphs in the font SFD files : https://github.com/primejyothi/glyphRen

It takes a reference file that contains the Unicode Code points and the corresponding names and rename the glyphs in the SFD file based on that. The composite characters will be renamed based on the constituent glyphs.

Hope this utility will make things little bit easy for the font maintainers.

This program is dedicated to Rajeesh for teaching me the first glyphs of Malayalam fonts.

November 25, 2013

Create smaller pdf files from pdf files that were generated out of images

Wrote this script a while back to shrink the pdf files provided by Kerala Sahitya Akademi, which were made entirely out of image files.
License : GPLv3

https://github.com/primejyothi/shrinkImgPdf

November 24, 2013

Script to extract list of Wikipedia users

userList.sh is a Bash script to download a XML file that lists the user names from the Malayalam Wikipedia with at least one edit. With appropriate change in the URL, it can be used for other languages Wiki's where the API is supported.

https://github.com/primejyothi/wikiUsers

September 2, 2013

ഗൂഗിൾ പിക്കാസ - പകരം എന്ത്?

പണ്ട് വിൻഡോസ് ഉപയോഗിക്കുന്ന കാലം മുതൽ ഫോട്ടോ കളക്ഷൻ മാനേജ് ചെയ്യാൻ ഉപയോഗിച്ചിരുന്നത് പിക്കാസയായിരുന്നു. മുഴുവനായി ലിനക്സിലേക്ക് മാറിയപ്പോഴും പിക്കാസയുടെ ലിനക്സ് വെർഷനായിരുന്നു ഉപയോഗിച്ചിരുന്നത്. കുറച്ചു കാലം മുമ്പ് ഗൂഗിൾ, പിക്കാസയുടെ ലിനക്സ് സപ്പോർട്ട് നിർത്തലാക്കിയെങ്കിലും വൈ‌‌ൻ ഉപയോഗിച്ച് പിക്കാസ ഫെഡോറയിൽ ഉപയോഗിച്ചിരുന്നു. അടുത്ത കാലത്ത് ഞാൻ ഫെഡോറ 19ലേക്ക് അപ്‌‌ഗ്രേഡ് ചെയ്തപ്പോൾ പിക്കാസ വീണ്ടും ഇൻസ്റ്റാൾ ചെയ്യേണ്ടി വന്നു. സിസ്റ്റത്തിലെ ഐഡികൾക്കെല്ലാം ഉപയോഗിക്കാവുന്ന വിധത്തിൽ പൊതുവായ ഒരു പിക്കാസ സെറ്റപ് ഉണ്ടാക്കുന്നത് വലിയ പണിയായതിനാൽ ഓരോ ഐഡികളിലും വൈൻ ഉപയോഗിച്ച് പിക്കാസ ഇൻസ്റ്റാൾ ചെയ്യേണ്ടി വന്നു. ഈ ബുദ്ധിമുട്ടുകാരണം പിക്കാസയ്ക്കു പകരം ഉപയോഗിക്കാവുന്ന സോഫ്റ്റ്വേറുകളെ കുറിച്ച് വീണ്ടും അന്വേഷണം തുടങ്ങി. മുമ്പ് F-Spot, gThumb, digiKam, Shotwell, Darktable ഒക്കെ നോക്കിയെങ്കിലും അതൊന്നും പിക്കാസ പോലെയാകുന്നുണ്ടായിരിന്നില്ല.

മുമ്പ് ഉപയോഗിച്ചു നോക്കിയവയിൽ ഏറ്റവും നല്ലതെന്നു തോന്നിയത് digiKam (http://digikam.org/) ആയിരുന്നു. അന്ന് അത് ഉപയോഗിക്കാതിരിക്കാനുള്ള കാരണം ഫോട്ടോകൾ എല്ലാം അത് ഒരു ഫോൾഡറിലേക്ക് ഇമ്പോർട്ട് ചെയ്യുമെന്നുള്ളതു കൊണ്ടാണ്. ഇമ്പോർട്ട് ചെയ്യാതെ നിലവലുള്ള ഫോൾഡറുക‌‌ൾ തന്നെ digiKamന് ഉപയോഗിക്കാൻ പറ്റുമെന്ന് മനസ്സിലായത് അടുത്തകാലത്താണ് (Settings -> Configure Digikam -> Collections -> Local Collections -> Add Collections). പിന്നെ താമസിച്ചില്ല, ഫോട്ടോകൾ മുഴുവനും ഡിജികാമിലേക്ക് കൊണ്ടുവന്നു.

പിക്കാസയുമായി താരതമ്യപ്പെടുത്തുമ്പോൾ ഡിജികാമിന്റെ എനിക്കിഷ്ടപ്പെട്ട ചില ഫീച്ചറുകൾ
  • ഫോട്ടോകളിലോ, ഫോൾഡറുകളിലോ മാറ്റങ്ങൾ വരുത്തുന്നില്ല. ഏതെങ്കിലും ഫോട്ടോ സ്റ്റാർ മാർക്ക് ചെയ്താൽ പിക്കാസ ആ ഫോട്ടോയുടെ ഫോൾഡറിൽ ഒരു ഫയൽ ഉണ്ടാക്കും. ഡിജികാം അതിന്റെ ഡേറ്റാബേസിലാണ് ഇത്തരം വിവരങ്ങൾ സൂക്ഷിക്കുക.
  • പിക്കാസയിൽ റോ ഫയലുകൾ കാണുമ്പോൾ  പിക്കാസ തന്നെ അതിൽ ചില കറക്ഷനുകൾ വരുത്തിയിട്ടാണ് ഡിസ്പ്ലേ ചെയ്യുക. ഈ കറക്ഷനുകളിൽ നമുക്ക് മാറ്റം വരുത്തുവാൻ പറ്റുമെന്നു തോന്നുന്നില്ല. ഡിജികാമിൽ ഇങ്ങനെ ഒരു പ്രശ്നമില്ല.
  • റോ ഫയലുകൾ പിക്കാസ* സെർച്ച് : പിക്കാസയിൽ ഉള്ളതിനേക്കാൾ വളരെ കൂടുതൽ സെർച്ച് ഓപ്ഷനുകൾ ഡിജികാമിനുണ്ട്. ഫോൾഡറിന്റെ പേരിന്റെ എവിടെനിന്നെങ്കിലുമുള്ളാ ഒരു ഭാഗം മാത്രം കൊടുത്താലും ഡിജികാം അതു കണ്ടുപിടിച്ചു തരും. Exif ഡേറ്റ ഉപയോഗിച്ചും സെർച്ച് ചെയ്യാവുന്നതാണ് (Search -> Advanced Search -> Photograp Information).
  • ചിത്രങ്ങൾ പിക്കാസ/ഫ്ലിക്കർ ഫേസ്ബുക്ക് എന്നിവയിലേക്ക് അപ്‌‌ലോഡ് ചെയ്യുക : ഡിജികാമുപയോഗിച്ച് വളരെയധികം സോഷ്യൽ നെറ്റ്വർക്ക് /ഫോട്ടോ ഷെയറിങ്ങ് സൈറ്റുകളിലേക്ക് ഫോട്ടോകൾ അപ്‌‌ലോഡ് ചെയ്യാൻ പറ്റും. ലിനക്സിൽ പിക്കാസയുടെ ലേറ്റസ്റ്റ് വെർഷനിൽ പിക്കാസ വെബിലേക്ക് അപ്‌‌ലോഡ് ചെയ്യാൻ പറ്റൂന്നില്ല എന്നുകൂടെ പറഞ്ഞുകൊള്ളട്ടേ.
  •  വീഡിയോകൾ : പിക്കാസയുടെ ലിനക്സ് വെർഷനിൽ വീഡിയോകൾ കാണാൻ പറ്റില്ലായിരുന്നു. ഡിജികാമിൽ നല്ല സുന്ദരമായി വീഡിയോകാണാം. വീഡിയോയുടെ തമ്പ്നെയിലുകൾ കാണണമെങ്കിൽ kffmpegthumbnailer അല്ലെങ്കിൽ  ffmpegthumbnailer എന്ന പാക്കേജ് ഇൻസ്റ്റാൾ ചെയ്യണം.
* അത്യാവശ്യം നല്ല വിധത്തിൽ ഇമേജ് ഏഡിറ്റിങും ചെയ്യാം.

June 15, 2013

ഫോട്ടോ റീസൈസിങ് - കമാന്റ് ലൈനിൽ നിന്നും

ഇമേജ് മാജിക് (ImageMagick) പാക്കേജിൽ ഉൾപ്പെട്ട ഒരു യൂട്ടിലിറ്റിയാണ് convert.
കമാന്റ്‌‌ ലൈനിൽ നിന്നും convert ഉപയോഗിച്ച് ഫോട്ടോകൾ റീസൈസ് ചെയ്യാൻ വളരെ എളുപ്പമാണ്. ഉദാഹരണത്തിന് 3888x2592 ഉള്ള big.jpg നെ 1200x800 ഉള്ള  small.jpg ആക്കുവാൻ താഴെ പറയുന്ന കമാന്റ് ഉപയോഗിക്കുക :

convert -resize 1200x800 big.jpg small.jpg

പ്രത്യേക ശ്രദ്ധയ്ക്ക് : രണ്ടാമത് കൊടുക്കുന്ന പേരിൽ ഫയൽ നിലവിലുണ്ടെങ്കിൽ അത് ഓവർറൈറ്റ് ചെയ്യപ്പെടും, അങ്ങനെ സംഭവിച്ചാൽ നേരത്തേയുണ്ടായിരുന്ന ഫയൽ പുന:സ്ഥാപിക്കാൻ പറ്റിയെന്നുവരില്ല.

May 27, 2013

ഓഫ്‌‌ലൈൻ മലയാളം നിഘണ്ടു

ഏതാനും ദിവസങ്ങൾക്ക് മുമ്പ് olam.in റിലീസ് ചെയ്ത (http://olam.in/open/datuk/‌‌) മലയാളം പദസമുച്ചയമുപയോഗിക്കുന്ന ഒരു ഓഫ്‌‌ലൈൻ മലയാളം - മലയാളം നിഘണ്ടു നിങ്ങൾക്കായി സമർപ്പിക്കുന്നു. ലിനക്സിനു വേണ്ടി എഴുതിയ ഈ പ്രോഗ്രാം വിൻഡോസിലേക്ക് ക്രോസ് കമ്പൈൽ ചെയ്തിട്ടുണ്ട്. അതിനാൽ വിൻഡോസിൽ ചില്ലറ കുഴപ്പങ്ങളുണ്ടായേക്കാം. താഴെ നല്കിയിട്ടുള്ള ലിങ്കുകളിൽ നിന്ന് ലിനക്സ്/വിൻഡോസ് വെർഷനുകൾ ഡൗൺലോഡ് ചെയ്യാവുന്നതാണ്.

ലിനക്സ് : http://goo.gl/yvCC9  (https://drive.google.com/folderview?id=0Bzw-OGqyq_FwTklzR0NCaDc1QVU&usp=sharing)

വിൻഡോസ് : http://goo.gl/B4R7l (https://drive.google.com/folderview?id=0Bzw-OGqyq_FwSTVxbGlSSlc3Y28&usp=sharing)

SQLite ഡേറ്റാബേസിലേക്ക് ഇംപോർട്ട് ചെയ്യാനുള്ള സ്ക്രിപ്റ്റുകൾ : http://goo.gl/fXhxr  (https://drive.google.com/folderview?id=0Bzw-OGqyq_FwTGsyZE02QWM5aDA&usp=sharing) ദതുക് കോർപ്പസ് ഫയലിൽ നിന്നും SQLite ലേക്ക് ഇംപോർട്ട് ചെയ്യുവാൻ മാത്രമേ ഈ സ്ക്രിപ്റ്റകൾ ആവശ്യമുള്ളൂ. നിഘണ്ടു പ്രോഗ്രാമിന് ഇവ ആവശ്യമില്ല.

Source code under GPL Licence : https://github.com/primejyothi/mlDict



May 13, 2013

ഡാറ്റാ റിക്കവറി പ്രോഗ്രാം

എസ് ഡി കാർഡിൽ നിന്നൊക്കെ ഫോട്ടോ, വീഡിയോ എന്നിവ റിക്കവർ ചെയാൻ : http://www.cgsecurity.org/wiki/PhotoRec

ഇതുപയോഗിച്ച് കറപ്റ്റായ ഒരു മൈക്രോ എസ് ഡി കാർഡിൽ നിന്നും ഫോട്ടോകളും വീഡിയോകളും പ്രശ്നമൊന്നുമില്ലാതെ റിക്കവർ ചെയ്തു. ഒരേ ഒരു പ്രശ്നം റിക്കവർ ചെയ്ത ഫയലുകളുടെ പേരുകൾ ഒരു വിധമായിരിക്കുമെന്നാണ്. exiftool ഉപയോഗിച്ച് ഫോട്ടോകളിൽ നിന്നും ഫോട്ടോ എടുത്ത സമയം എക്സ്റ്റ്രാറ്റ് ചെയ്ത് റീനേം ചെയ്ത്, ടൈം സ്റ്റാമ്പ് ഫോട്ടോ ഏടുത്ത സമയമാക്കി അപ്ഡേറ്റ് ചെയ്യാൻ ഒരു സ്ക്രിപ്റ്റെഴുതി ആ പ്രശ്നം സോൾവാക്കി.

സ്ക്രിപ്റ്റ് ആവശ്യമുള്ളവർക്ക് അത് ഇവിടെ നിന്ന് ഏടുക്കാം‌: http://goo.gl/Ud6IY

April 30, 2013

Connecting Android to Linux using MTP

Among the features those were lost during the upgrade from Ice Cream Sandwich to Jelly Bean, the one which I miss most was USB Mass Storage mode. It was the preferred method to backup the files from the Tab and sync the e-books to the Tab from Calibre Library. Calibre was pretty fast to provide support for MTP and syncing e-books were back to normal real soon.

However I was missing the USB mass storage mode as I could not access the files in the tab from the Linux command line for backing up the files. Finally I managed to get it working using mtpfs. The configuration was pretty straight forward but I could not get it work reliably. Most of the time I used to get the message "Transport endpoint is not connected" when trying to access the Tab from the command line. Finally found that mtpfs was crashing with core dump. Looks like the mtpfs for Fedora is broken. Even compiling the latest sources didn't help. Finally managed to get things going using go-mtpfs.

If you are trying to get mtpfs working in Fedora, try go-mtpfs : https://github.com/hanwen/go-mtpfs
Binaries of go-mtpfs are here : http://hanwen.home.xs4all.nl/public/software/go-mtpfs/

April 10, 2013

rsync ഉപയോഗിച്ചുള്ള ഡാറ്റാ ബാക്കപ്

നിങ്ങളുടെ ഡാറ്റയുടെ ബാക്കപ് എടുക്കണമെന്ന് ആഗ്രഹമുണ്ടോ? നിങ്ങൾ പതിവായി ഡാറ്റാ ബാക്കപ് ചെയ്യാറുണ്ടോ? എപ്പോഴെങ്കിലും കമ്പ്യൂട്ടറിന്റെയോ, ഡിസ്കിന്റെയോ തകരാർ കാരണം വിലപിടിച്ച ഡാറ്റാ നഷ്ടപെട്ടിട്ടുണ്ടോ? ഈ ചോദ്യങ്ങളിൽ ഒന്നിനെങ്കിലും അതെ എന്നാണ് നിങ്ങളുടെ ഉത്തരമെങ്കിൽ തുടർന്നു വായിക്കുക. എക്സ്റ്റേണൽ ഡ്രൈവൊക്കെ വാങ്ങി ബാക്കപ്പെടുക്കുന്നതൊക്കെ ചെലവുള്ള പണിയാണെന്നു വിചാരിക്കുന്നവരോട് ഒരു ചോദ്യം കൂടി - നിങ്ങളുടെ ഡാറ്റയാണോ എക്സ്റ്റേണൽ ഡ്രൈവാണോ കൂടുതൽ വിലപിടിച്ചത്?

ഡയറക്ടറികളും ഫയലുകളും മറ്റൊരു സ്ഥലത്തേക്ക് synchronize ചെയ്യുന്ന ഒരു പ്രോഗ്രാമാണ് rsync. മറ്റൊരു സ്ഥലമെന്നത് ഒരേ സിസ്റ്റത്തിലെ വ്യത്യസ്ത ഡയറക്ടറികളോ, രണ്ടു സിസ്റ്റങ്ങളിലെ ഡയറക്ടറികളോ തമ്മിലാകാം. rsync ഉപയോഗിച്ച്, സിസ്റ്റത്തിൽ ചേർത്തിട്ടുള്ള എക്സ്റ്റേണൽ ഡ്രൈവിലേക്ക് ഡാറ്റാ ബാക്കപ്പെടുക്കുന്നത് എങ്ങനെ എന്നാണ് ഈ പോസ്റ്റിൽ വിശദീകരിക്കുന്നത്.

/home/prime/data  എന്ന ഡയറക്ടറിയും അതിലെ ഉള്ളടക്കവും  /externaldrive/backup എന്ന ഡയറക്ടറിയിലേക്ക് ബാക്കപ്പെടുക്കുന്നത് എങ്ങനെ എന്നു നോക്കാം.

rsync -a /home/prime/data  /externaldrive/backup എന്ന കമാന്റ് റൺ ചെയ്താൽ ഡാറ്റ മുഴുവൻ /externaldrive/backup എന്ന ഡയറക്ടറിയിൽ എത്തിയിട്ടുണ്ടാകും. കുഴപ്പമൊന്നുമില്ലെങ്കിൽ ഈ കമാന്റ് നിശബ്ദമായി ഫയലുകൾ ലക്ഷ്യസ്ഥാനത്തേക്ക് പകർത്തും.  -a എന്നത് ആർക്കൈവ് മോഡിൽ ഡേറ്റാ പകർത്തുന്നതിനാണ്.  വളരെയധികം ഫയലുകൾ പകർത്തുമ്പോൾ rsync കുറച്ചധികം സമയമെടുത്തേക്കും. അപ്പോൾ rsync എന്താണ് ചെയ്യുന്നതെന്നറിയാൻ -v എന്ന കമാന്റ് ലൈൻ പരാമീറ്റർ കൊടുത്താൽ മതിയാകും.

rsync -av /home/prime/data  /externaldrive/backup  ഇപ്പോൾ ഫയലുകൾ പകർത്തുന്ന മുറയ്ക്ക് അവയെകുറിച്ചുള്ള വിവരങ്ങൾ rsync ടെമിനലിലേക്ക് എഴുതും.
rsync -av /home/prime/data  /externaldrive/backup > backup.log 2>&1 എന്നാക്കിയാൽ മെസ്സേജുകൾ backup.log എന്ന ഫയലിലേക്ക് എഴുതും.

rsync ആദ്യം ഒരു ഡയറക്ടറിയുടെ ബാക്കപ്പെടുക്കുമ്പോൾ കുറച്ചധികം സമയമെടുക്കും. പിന്നീടുള്ള ബാക്കപ്പുകളിൽ പുതിയ ഫയലുകളും മാറ്റമുള്ള ഫയലുകളും മാത്രം പകർത്തുമെന്നതിനാൽ കൂടുതൽ വേഗത്തിൽ ബാക്കപ് നടക്കും. പുതിയ ഫയലുകളും മാറ്റമുള്ള ഫയലുകളും  rsync തന്നെ കണ്ടുപിടിക്കുമെന്നതിനാൽ യൂസറിന് അതിനെക്കുറിച്ചാലോചിച്ച് ബുദ്ധിമുട്ടേണ്ടതില്ല. ഈ തരത്തിൽ ബാക്കപ്പെടുക്കുമ്പോൾ മാറിയ ഫയലുകൾ ലക്ഷ്യസ്ഥാനത്തുള്ള ഫയലുകളെ മാറ്റുമെന്നതിനാൽ മാറ്റങ്ങളും  പകർത്തപ്പെടും. ഉദാഹരണത്തിന് ബിരിയാണി എന്ന ഫയലിൽ പത്ത് വരികൾ ഉണ്ടായിരുന്നെന്നു കരുതുക. ആദ്യത്തെ ബാക്കപ്പിനു ശേഷം അബദ്ധവശാൽ അതിലെ നാലു വരികൾ മായ്കക്കപ്പെട്ടു എന്നു കരുതുക. അടുത്ത പ്രാവശ്യം rsync ചെയ്യുമ്പോൾ ലക്ഷ്യസ്ഥാനത്തിലെ പത്തു വരിയുള്ള ബിരിയാണി ആറു വരികളുള്ള ബിരിയാണിയായി മാറും. --backup, --backup-dir --suffix എന്നീ ഓപ്ഷനുകളുപയോഗിച്ച് താഴെ പറയുന്ന രീതിയിൽ ഈ പ്രശ്നം ഒരു പരിധിവരെ പരിഹരിക്കാവുന്നതാണ്.

rsync -av --backup --backup-dir=/externaldrive/changes --suffix=.bkup /home/prime/data  /externaldrive/backup

ഇപ്പോൾ മാറ്റമുള്ള ഫയലുകളുടെ പഴയ കോപ്പികൾ /externaldrive/changes എന്ന ഡയറക്ടറിയിൽ .bkup എന്ന എക്സ്റ്റൻഷനോടെ  ഉണ്ടാകും. changes ഡയറക്ടറിയുടെ ഘടന /home/prime/data എന്ന ഡയറക്ടറിയുടേതു പോലെ ആയിരിക്കും. നേരത്തേ പറഞ്ഞ നമ്മുടെ ബിരിയാണി ഫയൽ /home/prime/data/recipe/biriyani എന്നാണെങ്കിൽ ആറുവരിയുള്ള പുതിയ ബിരിയാണി ഫയൽ  /externaldrive/backup/data/recipe/biriyani ആയും  /externaldrive/backup/data/recipe/biriyani ഇൽ നേരത്തേ ഉണ്ടായിരുന്ന പത്തു വരി ബിരിയാണി  /externaldrive/changes/data/recipe/biriyani.bkup എന്ന പേരിലും ഉണ്ടാകും. ഓരോ തവണയും suffix .bkup എന്നായതിനാൽ /externaldrive/changes ഡയറക്ടറിയിൽ തൊട്ടുമുമ്പത്തെ വെർഷൻ മാത്രമേ ഉണ്ടാകൂ. .bkup എന്നതിനു പകരം ഡേറ്റും സമയവും   --suffix ആയി ഉപയോഗിച്ചാൽ എല്ലാ വെർഷനും കിട്ടും.

rsync -av --backup --backup-dir=/externaldrive/changes --suffix= .bkup.`date "+%Y%m%d%H%M%S"` /home/prime/data  /externaldrive/backup

ഇപ്പോൾ ബാക്കപ്പുകൾക്ക് .bkup.YYYYMMDDHHMISS എന്ന രീതിയിൽ എക്സ്റ്റൻഷനുണ്ടാകും.

വെവ്വേറെ ഡയറക്ടറികളുടെ ബാക്കപ്പെടുക്കാൻ ഡയറക്ടറികളുടെ പേരു മാറ്റി rsync റൺ ചെയ്താൽ മതിയാകും. ഇനി ഇതെല്ലാം കൂടി ഒരു ഫയലിലാക്കി കിട്ടിയാൽ കൊള്ളാമെന്നുണ്ടെങ്കിൽ ചെറിയ വ്യത്യാസങ്ങളോടു കൂടി backupScript.sh എന്ന പേരിൽ സംഭവം ഇവിടെ (http://goo.gl/rUdqe) ഉണ്ട്[1].  പല ഡയറക്ടറികൾ സപ്പോർട്ട് ചെയ്യാനായി വിവരങ്ങൾ ഒരു പ്രൊഫൈൽ ഫയലിൽ നിന്ന് റീഡ് ചെയ്യുന്നു. പല ഡിസ്കുകൾക്കായി വെവ്വേറെ പ്രൊഫൈൽ ഫയലുകൾ ഉണ്ടാക്കാവുന്നതാണ്. ഒരു സാമ്പിൾ ഫയൽ extDrive.profile എന്ന പേരിൽ ഇവിടെയുണ്ട് : http://goo.gl/zewX7

സ്ക്രിപ്റ്റ് റൺ ചെയ്യുന്ന വിധം.
1. സ്ക്രിപ്റ്റും സാമ്പിൾ പ്രൊഫൈലും ഡൗൺലോഡ് ചെയ്യുക.
2. chmod u+x backupScript.sh എന്നു കമാന്റ് റൺ ചെയ്യുക. സ്ക്രിപ്റ്റ് ഫയലിന്  എക്സിക്യൂട്ട് പെർമിഷൻ കൊടുക്കാനാണിത്.
3. ഏതെങ്കിലും ടെക്സ്റ്റ് എഡിറ്റർ ഉപയോഗിച്ച് സാമ്പിൾ പ്രൊഫൈലിൽ (extDrive.profile) ആവശ്യം വേണ്ട മാറ്റം വരുത്തുക.
    അ. CTRL|backupdir|/externaldrive/changes എന്ന ലൈനിലെ /externaldrive/changes എന്ന പഴയ വെർഷനുകൾ സൂക്ഷിക്കുന്ന ഡയറക്ടറിയുടെ പേര് നിങ്ങളുടെ ആവശ്യാനുസരണം മാറ്റുക.
    ആ. /home/user/data|/externaldrive/bkup എന്ന ലൈനിൽ ആദ്യത്തെ ഡയറക്ടറി ബാക്കപ്പെടുക്കേണ്ട ഡയറക്ടറിയാണ്. രണ്ടാമത്തേത് ലക്ഷ്യസ്ഥാനവും. ഇതു രണ്ടും തമ്മിൽ വേർതിരിക്കുന്നത് പൈപ്പ് (|) ഉപയോഗിച്ചാണ്. പൈപ്പ് ഇല്ലെങ്കിൽ സ്ക്രിപ്റ്റ് ശരിയായി പ്രവർത്തിക്കില്ല.
    ഇ. കൂടുതൽ ഡയറക്ടറികൾ ബാക്കപ്പെടുക്കണമെങ്കിൽ കൂടുതൽ ലൈനുകൾ ചേർക്കാവുന്നതാണ്.
    ഈ. ലൈനുകൾ കമന്റു ചെയ്യാൻ ലൈനിന്റെ ആദ്യം # ചേർത്താൽ മതി.
4. backupScript.sh extDrive.profile എന്നു ടെർമിനലിൽ റൺ ചെയ്യുക.

[1] rsyncഉം  ഈ സ്ക്രിപ്റ്റിന്റെ മുൻഗാമികളും  കാരണമാണ് രണ്ടു പ്രാവശ്യം ലാപ്ടോപ് അടിച്ചു പോയിട്ടും, പല പ്രാവശ്യം എക്സ്റ്റേണൽ/ഇന്റെണൽ ഡ്രൈവുകൾ കുളമാ(ക്കി)യിട്ടും എന്റെ ഡാറ്റ സുരക്ഷിതമായിരിക്കുന്നതെന്ന് നന്ദിപൂർവം സ്മരിച്ചുകൊള്ളുന്നു.

May 16, 2012

push & pop - cd made bit easier

During my initial days as developer, I found myself doing cd to folders which were deep in the directory structures often having long names. Long names were not a big problem due to auto completion but remembering different directory names were a problem. The idea of having aliases for cd for different directories was dropped even before writing a single alias as I didn't want to remember the aliases for different directories. So I wrote two scripts named push.sh and pop.sh. The working is pretty simple, you go to a directory which need to be remembered, execute push. The pop script will give a list of remembered directories and based on the choice will take you to the selected directory. I hope you may find this useful. Here are the scripts:

[prime@ford bin]$ cat push.sh 
#! /bin/bash
lines_to_keep=9
data_file=~/.dir.dat
tmp_file=~/.dir.dat.$$ 
tail -"$lines_to_keep" $data_file > $tmp_file
mv $tmp_file $data_file
cur_dir=`pwd`
echo $cur_dir >> $data_file

[prime@ford bin]$ cat pop.sh 
#! /bin/bash
lines_to_keep=9
data_file=~/.dir.dat
tail -"$lines_to_keep" $data_file |nl
echo -e "Choice please : " \\c
read choice
case "$choice" in
[0-9]*)
        ;;
*)
        echo "Invalid choice"
        return 0
        ;;
esac
dest_dir=`tail -"$lines_to_keep" $data_file | head -$choice |tail -1`
cd $dest_dir

Save scripts in a convenient location say ~/bin. The pop.sh script need to run in the current shell the cd to work correctly. This can be either be done by preceding the pop.sh with a dot (not very convenient) or creating an alias which will run the script in the current shell as follows

alias pop='. ~/bin/pop.sh'
alias push='~/bin/push.sh' # Put these aliases in the .bashrc or .profile

Hope you may find it useful. Share and enjoy!*

* "Share and Enjoy" is the slogan of the Sirius Cybernetics Corporation ;)