Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Sunday, 4 December 2016

create a OS managed service using systemd

  1. UNIX System V OS/ BSD OS init systems,
  2. upstart, 2006, an event-based replacement for the traditional init daemon upstart.
    The recent version of ubuntu uses systemd, as far as I remember previous versions of ubuntu use upstart.
  3. runit, 2004
  4. launchd in MacOS world.
PS. There's lot of hate against systemd, it being against Unix philosophy that goes as;
Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.
Here's a thread which might be useful to dig.

Fun time

I'm creating a streaming service in this example, which will simply write an event to a file continuously. And, if I restart my machine the service will start emitting events to a file right away.
Also I can start or stop service using systemctl start/stop serviceName. I used to use nohup <command> & and to kill it I had to use get the PID and then kill it. I can get rid of all that crap with systemD service.
STEP 1 - create streaming.service at /etc/systemd/system/multi-user.target.wants/streaming.service, also at /etc/systemd/system/streaming.service.
[Unit]                                                                                                                                           
Description=Streaming pipeline                                                                      

[Service] 
Type=forking                                                                         
ExecStart=/usr/local/bin/streaming.sh
TimeoutSec=infinity
Restart=always

[Install]
WantedBy=multi-user.target
STEP 2 - create a bash script at /usr/local/bin/streaming.sh and give current user permission to it. Don't forget #!/bin/bash for the bash scripts.
#!/bin/bash
while true
 do
    echo "Streaming an event at `date`" >> /var/log/streaming.log
 done
chmod 777 /usr/local/bin/streaming.sh
STEP 3 - reload systemd daemon so that it loads streaming.service and enable the service
systemctl daemon-reload
systemctl enable streaming.service
STEP 4 - see the streaming job status
systemctl status streaming.service
I can use journalctl _PID=?? to debug if the service is not working. eg.
journalctl _PID=5871
-- Logs begin at Mon 2016-11-21 16:36:41 PST, end at Tue 2016-12-06 14:34:56 PST. --
Nov 26 04:17:52 y0319t10971 sshd[5871]: Connection closed by 10.16.132.191 [preauth]
Dec 06 14:33:15 y0319t10971 systemd[5871]: Failed at step EXEC spawning /usr/local/bin/streaming.sh: Exec format error
or also can use following command,
root@y0319t10971:~# journalctl -fu streaming.service
-- Logs begin at Mon 2016-11-21 16:36:41 PST. --
Dec 06 14:33:16 y0319t10971 systemd[1]: streaming.service: main process exited, code=exited, status=203/EXEC
Dec 06 14:33:16 y0319t10971 systemd[1]: Unit streaming.service entered failed state.
Dec 06 14:33:16 y0319t10971 systemd[1]: streaming.service failed.
Dec 06 14:34:28 y0319t10971 systemd[1]: Started Streaming pipeline.
Dec 06 14:34:28 y0319t10971 systemd[1]: Starting Streaming pipeline...
Dec 06 14:34:28 y0319t10971 systemd[1]: streaming.service: main process exited, code=exited, status=203/EXEC
Dec 06 14:34:28 y0319t10971 systemd[1]: Unit streaming.service entered failed state.
Dec 06 14:34:28 y0319t10971 systemd[1]: streaming.service failed.
Dec 06 14:44:58 y0319t10971 systemd[1]: Started Streaming pipeline.
Dec 06 14:44:58 y0319t10971 systemd[1]: Starting Streaming pipeline...
STEP 5 - see the events produced by the streaming.service
tail -f /var/log/streaming.log 
Streaming an event at Fri Dec  2 11:27:21 PST 2016
Streaming an event at Fri Dec  2 11:27:21 PST 2016
Streaming an event at Fri Dec  2 11:27:21 PST 2016
Streaming an event at Fri Dec  2 11:27:21 PST 2016
Streaming an event at Fri Dec  2 11:27:21 PST 2016
Streaming an event at Fri Dec  2 11:27:21 PST 2016
Streaming an event at Fri Dec  2 11:27:21 PST 2016
Streaming an event at Fri Dec  2 11:27:21 PST 2016
Streaming an event at Fri Dec  2 11:27:21 PST 2016
Streaming an event at Fri Dec  2 11:27:21 PST 2016
PS. Dont forget to stop the service, otherwise your Storage will be full in few days :)
ll /var/log/streaming.log --block-size=GB
-rw-r--r-- 1 root root 3GB Dec  6 13:51 /var/log/streaming.log
Also, the service would be running right after I reboot the machine.

Saturday, 24 September 2016

Virtualization 101

What is virtualization?
The idea of virtualization is to to be able to run virtual computers on existing piece of physical machine. One computer will get one IP address, with virtualization I can have multiple IPs on same hardware.

I first knew of virtualization while working on software for banks. The "IT department" of bank would create a VM for me to install software :)


Setting up VM

Install VirtualBox which is a full virtualizer https://www.virtualbox.org/wiki/Downloads

Then download the ISO for OS you want to have a VM for and attach it to VirtualBox storage as shown in screenshot below(In MacOS). Ubuntu ISO can be downloaded from here, https://www.ubuntu.com/download/desktop




http://askubuntu.com/questions/825437/ubuntu-16-in-vm-does-not-have-access-to-internet

Regarding the Network setup, it really depends on the nature of the network being used. In following example, in one case wireless works for me.


while in wired environment ethernet adaptor works.



Resizing the VM
In case you need to increase the VM RAM or Disk size, after you created your VM, then follow the process as below :

STEP 1 : shut down VM

STEP 2 : resize the VM vdi using host terminal (windows in mycase)
VBoxManage modifyhd "C:\Users\AS18\VirtualBox VMs\WM_Bridge\WM_Bridge.vdi" --resize 100000

STEP 3 : 
Then, using gparted resize the /dev/sda1

Original config


Delete linux-swap



Reassign the size to linux-swap









http://askubuntu.com/a/558215/37643

http://askubuntu.com/a/95026/37643

Share folder
---------------------

1) Install guest edition



followed by sudo /media/prayagupd/VBOXADDITIONS_5.1.8_111374/VBoxLinuxAdditions.run and then reboot.

How to Access Folders on Your Host Machine from an Ubuntu Virtual Machine in VirtualBox

2) add current guest user to the vboxsf usergroup

sudo adduser $USER vboxsf
[sudo] password for prayagupd:
Adding user `prayagupd' to group `vboxsf' ...
Adding user prayagupd to group vboxsf
Done.

verify that its working, 
id $USER
uid=1000(prayagupd) gid=1000(prayagupd) groups=1000(prayagupd),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),128(sambashare),999(vboxsf)

3) mount shared folder

Create a mount folder on host machine with Auto-mount Yes, and Access Full.








Wednesday, 25 November 2015

CPU cores in OSX

Seems OSX sucks in command line support as Linux does. However, found few commands to get hw information in OSX.

sysctl -n hw.ncpu
8

sysctl -n hw.physicalcpu
4

sysctl -n hw.logicalcpu
8


Ref : https://coolaj86.com/articles/get-a-count-of-cpu-cores-on-linux-and-os-x/

Monday, 21 October 2013

First night hack on elasticsearch (3 hrs)

ElasticSearch is (Apache Solr like) Lucene based distributed RESTful (PUT, GET, POST, DELETE) search server developed in Java.
To get motivated read a soundcloud casestudy and watch Search and Discovery at SoundCloud.

Elasticsearch in 15 minutes from David Pilato is a nice resource to follow.





Following Slide is also a useful one(with Rails tutorial - slides#44).



Now, Let's get hands dirty.

[STEP 1] download and tar elasticsearch 0.90.5
prayag@prayag:~$ wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.5.tar.gz

prayag@prayag:~$ tar -zxvf elasticsearch-0.90.5.tar.gz

[STEP 2] start elasticsearch node (in foreground)
prayag@prayag:~$ elasticsearch-0.90.5/bin/elasticsearch -f
[2013-10-21 23:19:19,127][INFO ][node                     ] [Aardwolf] version[0.90.5], pid[15897], build[c8714e8/2013-09-17T12:50:20Z]
[2013-10-21 23:19:19,128][INFO ][node                     ] [Aardwolf] initializing ...
[2013-10-21 23:19:19,140][INFO ][plugins                  ] [Aardwolf] loaded [], sites []
[2013-10-21 23:19:23,523][INFO ][node                     ] [Aardwolf] initialized
[2013-10-21 23:19:23,524][INFO ][node                     ] [Aardwolf] starting ...
[2013-10-21 23:19:23,800][INFO ][transport                ] [Aardwolf] bound_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish_address {inet[/192.168.195.8:9300]}
[2013-10-21 23:19:27,045][INFO ][cluster.service          ] [Aardwolf] new_master [Aardwolf][pK-h7KRwTWamnQNNrR2gwQ][inet[/192.168.195.8:9300]], reason: zen-disco-join (elected_as_master)
[2013-10-21 23:19:27,143][INFO ][discovery                ] [Aardwolf] elasticsearch/pK-h7KRwTWamnQNNrR2gwQ
[2013-10-21 23:19:27,233][INFO ][http                     ] [Aardwolf] bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/192.168.195.8:9200]}
[2013-10-21 23:19:27,234][INFO ][node                     ] [Aardwolf] started


[2013-10-21 23:19:27,311][INFO ][gateway                  ] [Aardwolf] recovered [0] indices into cluster_state

Verify elasticsearch is running at 9200, 
First You may need to install curl ,
sudo apt-get update
sudo apt-get install curl

Then, curl following request in terminal,
$ curl -XGET 'http://localhost:9200'
{
  "ok" : true,
  "status" : 200,
  "name" : "Lady Octopus",
  "version" : {
    "number" : "0.90.5",
    "build_hash" : "c8714e8e0620b62638f660f6144831792b9dedee",
    "build_timestamp" : "2013-09-17T12:50:20Z",
    "build_snapshot" : false,
    "lucene_version" : "4.4"
  },
  "tagline" : "You Know, for Search"
}

[STEP 3] create index movies

Then, put following script in create_index.sh, and then execute the same.
curl -XPUT 'http://localhost:9200/movies/'

$ bash create_index.sh

[STEP 4] apply mapping for type 'Movie'
Put following script in movie_mapping.sh, and then execute the same.

curl -X PUT localhost:9200/movies/Movie/_mapping -d '{
    "Movie" : { "properties"  : { 
                    "title"    : { "type":"String" }, 
                    "director" : { "type":"String" }, 
                    "year"     : { "type":"long" }
                }
              }
}'

$ bash movie_mapping.sh


[STEP 5] Indexing(create/update) documents 
$ curl -XPUT http://localhost:9200/<index>/<type>/<id>,
where type(in ES) = table (in RDBMS)

Put following script in movie_document.sh, and then execute the same.
curl -XPUT 'http://localhost:9200/movies/Movie/1' -d '
{
    "title": "The Godfather",
    "director": "Francis Ford Coppola",
    "year": 1972
}'

$ bash movie_document.sh

Response we get is, 
{"ok":true,"_index":"movies","_type":"Movie","_id":"1","_version":1}

And, check the elasticsearch console with following updates.
[2013-10-22 00:12:46,835][INFO ][cluster.metadata         ] [Aardwolf] [movies] creating index, cause [auto(index api)], shards [5]/[1], mappings []
[2013-10-22 00:12:47,944][DEBUG][action.index             ] [Aardwolf] Sending mapping updated to master: index [movies] type [movie]
[2013-10-22 00:12:47,961][INFO ][cluster.metadata         ] [Aardwolf] [movies] update_mapping [movie] (dynamic)


[STEP 6.1] Retrieve document by id
Syntax : 
$ curl -XGET http://localhost:9200/<index>/<type>/<id>

Execute following command to retrieve movie with document id 1,
$ curl -XGET "http://localhost:9200/movies/Movie/1?pretty=true"
{
  "_index" : "movies",
  "_type" : "Movie",
  "_id" : "1",
  "_version" : 1,
  "exists" : true, 
"_source" : 
{
    "title": "The Godfather",
    "director": "Francis Ford Coppola",
    "year": 1972 
}
}

[STEP 6.2] Search documents by type field (title)
$ curl -XGET "localhost:9200/movies/Movie/_search?q=title:Godfather"

 {"took":22,
"timed_out":false,
"_shards":{"total":5,"successful":5,"failed":0},
"hits":{
"total":1,
"max_score":0.30685282,
"hits":
[{"_index":"movies",
"_type":"Movie",
"_id":"1",
"_score":0.30685282, 
"_source" : 
{
    "title": "The Godfather",
    "director": "Francis Ford Coppola",
    "year": 1972 
}
}]
}
}


OR Using Elasticsearch Query DSL, 





[7] Not to miss 
[7.1] 40 mins presentation by +Shay Banon 


                                   Shay Banon - ElasticSearch: Big Data, Search, and Analytics

The presentation includes following topics : 
data design patterns
The "kagillion" shards problem
Simple data flows
"Users" data flow
"time" data flow (clicks etc)
more than search
questions?
etc

[7.2] ElasticSearch, "You know, for search", Presentation by Clinton Gormley
Also watch this guy at "Getting down and dirty with Elasticsearch"





[7.3] book exploring elasticsearch, Andrew Cholakian



References
ElasticSearch 101– a getting started tutorial, http://joelabrahamsson.com/elasticsearch-101/

ElasticSearch in 5 minutes, http://www.elasticsearchtutorial.com/elasticsearch-in-5-minutes.html

http://blog.florian-hopf.de/2013/09/simple-event-analytics-with.html

http://www.javacodegeeks.com/2013/04/getting-started-with-elasticsearch.html

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-health.html

http://thediscoblog.com/blog/2013/09/03/effortless-elasticsearch-clustering/

Scaling massive elastic search clusters - Rafał Kuć - Sematext, http://www.slideshare.net/kucrafal/scaling-massive-elastic-search-clusters-rafa-ku-sematext



Shards and replicas in Elasticsearch, http://stackoverflow.com/a/15705989/432903

Saturday, 5 October 2013

Understanding Unix - Part 2 (for programmers)

This post is a sequel of previous post Linux Hacks Part 1 mostly important for programmers.


hack 1 => copy text to the clip(board)
Copy text from file Service.groovy,
$ xclip -selection clipboard grails-app/domain/eccount/Service.groovy

Paste to a new file ServiceNew.groovy
$ vi grails-app/domain/eccount/ServiceNew.groovy

Go INSERT mode and Ctrl+Shift+V

OR

gg"*yG

Reference  :
xclip Does Copy-and-Paste on the Linux Command Line, http://www.linuxplanet.com/linuxplanet/tips/6788/1
VI editor: Copy all the lines to clipboard,  http://stackoverflow.com/a/1620029/432903

hack 2 => find files with a name inside a directory
find searches in the real system.
is slower but always up-to-date and has more options (size, modification time,...)

eg. 1
loohcs$ find . -name "*Service*"
./test/unit/eccount/StudentServiceTests.groovy
./test/unit/eccount/UserServiceTests.groovy
./grails-app/domain/eccount/Service.groovy
./grails-app/domain/eccount/ServiceTransaction.groovy
./grails-app/services/eccount/TransactionService.groovy
./grails-app/services/eccount/UserService.groovy

eg. 2
$ find /packup/repo.softwares/ -name "*cassandra*"
/packup/repo.softwares/JVM/SolrLuceneES-BigData/apache-cassandra-2.0.6-bin.tar.gz
/packup/repo.softwares/JVM/SolrLuceneES-BigData/apache-cassandra-2.0.7-bin.tar.gz

Reference 10:
10 find command in unix examples basic, http://javarevisited.blogspot.com/2011/03/10-find-command-in-unix-examples-basic.html

What is the different between 'locate' and 'find' in Linux?, http://superuser.com/a/199473

hack 3 => awk (intrepreted prog lang)
find the total number of lines in a file (without using NR)
prayag@prayag:~/hacker_/loohcs$ awk 'BEGIN {sum=0} {sum=sum+1} END {print sum}' grails-app/controllers/LoginController.groovy 
134

hack 4 => SED (Stream EDitor) 
4.1) replace the word "ServiceTransaction" with "Transaction" in file


Stream editor is Stream editor not file editor.

root@0cad383c1249:/# sed --version
sed (GNU sed) 4.4
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jay Fenlason, Tom Lord, Ken Pizzini,
and Paolo Bonzini.
GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-sed@gnu.org>.

prayag@prayag:~/hacker_/loohcs$ sed s/ServiceTransaction/Transaction/ < TransactionService.groovy

## OR 
$ echo "Mbr Hlth Screening Mammogram" | sed s/Hlth/Health/ | sed s/Mbr/Member/
Member Health Screening Mammogram


## OR replace a word with special character containing $
sed --in-place 's/shaharma/\$ORGANISATION_NAME/' deployment.sh

4.2) delete empty lines
$ sed '/^$/d' src/main/resources/MoneyReply.xml > src/main/resources/MoneyReplyOut.xml

Practice more at Sed Interview Questions

4.3) remove certain chars

## Following is a script to remove character ) 
$ sed 's/[),]//g' Diagnosis.html

## remove \ character in serialised json,
sed 's/[\\]//g' < data

4.4) replace a line with certain content
Syntax -
sed -i '/TEXT_OF_A_LINE_TO_BE_REPLACED/c\prayagupd just changed this line.' FILE_NAME

eg.
sed --in-place '/Dvbox/c\   "-Dvbox.home=/usr/lib/virtualbox"' project.clj

on macos,

sed -i.bu 's/Dvbox/yo/' project.clj

grep using sed
sed -n '/Chrome/p' < apple.log | tee newApple.log

hack 5 => ssh connect
$ ssh -v uatestinguser@10.13.222.123

Copy file from remote linux server to local machine
$ scp -v uatestinguser@10.13.222.250:/tmp/analytics.csv /home/prayag/

Reference reading : 
Section 1.2: How do SSH, Telnet and Rlogin differ?,  http://cc-ipcp.icp.ac.ru/Section1.2.html
The SSH (Secure Shell) vs RemoteLogin Protocol, http://www.slideshare.net/sourav894/ssh-and-rlogin
3.3 Setting up permissions for rsh, rlogin and rcp(.rhosts), http://rmni.iqfr.csic.es/guide/man/lynux/chap3-3.htm

hack 6 > ls 
list files sorted by date in desc order
$ ls -tr

hack 7 => length of a string

(length of Long.MAX_VALUE in java)

echo "9223372036854775807" | wc -c

      20

$ expr length '$2a$10$osjPAbnn9ogMsY7z.Q7rWe2FLTx/C9Yi6.mj74aTbXWC3iyR1p/0q'
60

hack 8 => find a file with particular text 
The grep syntax looks as below.
$ grep -r "<SEARCH_TEXT>" <DIRECTORY_PATH>

$ grep -r "navbar-merchant" nioc2egdelonk/
nioc2egdelonk/web-app/less/nav.less:.navbar-admin {

hack 9 : know gtk version
$ dpkg -l libgtk[0-9]* | grep ^i
ii  libgtk2-perl                           2:1.223-1build3                         Perl interface to the 2.x series of the Gimp Toolkit library
ii  libgtk2.0-0                            2.24.10-0ubuntu6                        GTK+ graphical user interface library
ii  libgtk2.0-bin                          2.24.10-0ubuntu6                        programs for the GTK+ graphical user interface library
ii  libgtk2.0-common                       2.24.10-0ubuntu6                        common files for the GTK+ graphical user interface library

hack 10 : install gtk-recordmydesktop
$ sudo apt-get install gtk-recordmydesktop

Configure laptop settings as mentioned at recordMyDesktop output video shows *massive* artifacts, else plays too fast lowering resolution to to 1360x768.
$ xrandr -s 1360x768



Start recordmydesktop 
$ gtk-recordmydesktop -o /home/prayag/Videos/gwt_screencast.ogv

Convert *.ogv to *.flv with same-quality (size will increase though)
$ ffmpeg -sameq -i /home/prayag/Videos/gwt_screencast.ogv /home/prayag/Videos/gwt_screencast.flv

hack 11 : Zip a file
$  zip -r eccount-hg *



References
How can I create launchers on my desktop?, http://askubuntu.com/a/64237/37643
Csv to Html Table, https://gist.github.com/prayagupd/8050493

Friday, 16 August 2013

Making Ncell Connect work for linux

Making Ncell Connect work for linux

STEP 1 : install usb-modeswitch
USB_ModeSwitch is a mode switching tool for controlling "flip flop" (multiple device) USB gear.

$ sudo -s
$ apt-get install usb-modeswitch

STEP 2 : cat rules for ncell-connect

root@prayag:~# cat > /etc/udev/rules.d/99-ncell-connect.rules <<EOT
 # Ncell Connect switch mode to usbserial (E1550 device id => 12d1:1446)
 SUBSYSTEM=="usb", ATTRS{idProduct}=="1446", ATTRS{idVendor}=="12d1", RUN+="/lib/udev/modem-modeswitch --vendor 0x12d1 --product 0x1446 --type option-zerocd"
 EOT

STEP 3 configure network provider
Insert the device and goto Network settings at right corner of ubuntu 12.04.

Create a broadband connection under Mobile Broadband.



Then select country as Nepal, network provider as Mero Mobile, and billing plan as default.



REFERENCES
[1] Mobile Broadband Set-up In Ubuntu 11.04
http://www.muktware.com/1063/mobile-broadband-set-ubuntu-1104

[2] How to auto connect Ubuntu 12.04 USB GSM Mobile Broadband Connection on Boot as startup service without user login using Network Manager CLi,
http://www.thefanclub.co.za/how-to/how-auto-connect-ubuntu-1204-gsm-mobile-broadband-connection-on-boot-startup-service

[3] SMS From Ncell Connect Data SIM Card And Ubuntu How To, (September 7, 2011)
http://techspalace.blogspot.com/2011/09/sms-from-ncell-connect-data-sim-card.html

Friday, 29 March 2013

Android Command Line Hacks

Android Command Line Hacks

[1] Update Project

Create a new project from existing code,

ANDROID_HOME=/home/prayag/android-sdks/
prayag@prayag:/BirthdayForestGap$ $ANDROID_HOME/tools/android update project --path ../BirthdayForestGap/
Updated local.properties
No project name specified, using Activity name 'BirthdayForestViewController'.
If you wish to change it, edit the first line of build.xml.
Added file ../BirthdayForestGap/build.xml
Updated file ../BirthdayForestGap/proguard-project.txt
It seems that there are sub-projects. If you want to update them
please use the --subprojects parameter.

If you are using android studio in mac, the location of sdk is

λ ls -l /Users/prayagupd/Library/Android/sdk/
total 0
drwxr-xr-x   7 prayagupd  184630988  224 Sep  8 09:08 build-tools
drwxr-xr-x  17 prayagupd  184630988  544 Jan 10  2018 emulator
drwxr-xr-x   6 prayagupd  184630988  192 Jan 10  2018 extras
drwxr-xr-x   3 prayagupd  184630988   96 Jan 10  2018 fonts
drwxr-xr-x   4 prayagupd  184630988  128 Jan 10  2018 licenses
drwxr-xr-x   3 prayagupd  184630988   96 Jan 10  2018 patcher
drwxr-xr-x  19 prayagupd  184630988  608 Jan 21  2019 platform-tools
drwxr-xr-x   7 prayagupd  184630988  224 Nov  9 10:29 platforms
drwxr-xr-x  26 prayagupd  184630988  832 Jun 16  2019 skins
drwxr-xr-x   5 prayagupd  184630988  160 Jun 17  2019 sources
drwxr-xr-x   3 prayagupd  184630988   96 Jan 10  2018 system-images
drwxr-xr-x  14 prayagupd  184630988  448 Jan 10  2018 tools

[2] ASM - Android SDK Manager
prayag@prayag: /BirthdayForestGap$ $ANDROID_HOME/tools/android sdk




prayag@prayag: /BirthdayForestGap$ ps aux | grep android
prayag   13409  2.6  1.9 473456 74852 pts/3    Sl+  22:16   0:20 java
-Xmx256M
-Dcom.android.sdkmanager.toolsdir=/home/prayag/android-sdks/tools
-classpath /home/prayag/android-sdks/tools/lib/sdkmanager.jar:/home/prayag/android-sdks/tools/lib/swtmenubar.jar:/home/prayag/android-sdks/tools/lib/x86/swt.jar com.android.sdkmanager.Main
prayag   13749  0.0  0.0   4400   836 pts/1    S+   22:29   0:00 grep --color=auto android


You can list sdks
ANDROID_HOME=/usr/local/android-studio/sdk
$ $ANDROID_HOME/tools/android list sdk
Refresh Sources:
  Fetching https://dl-ssl.google.com/android/repository/addons_list-2.xml
  Validate XML
  Parse XML
  Fetched Add-ons List successfully
  Refresh Sources
  Fetching URL: https://dl-ssl.google.com/android/repository/repository-8.xml
  Validate XML: https://dl-ssl.google.com/android/repository/repository-8.xml
  Parse XML:    https://dl-ssl.google.com/android/repository/repository-8.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/addon.xml
  Validate XML: https://dl-ssl.google.com/android/repository/addon.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/addon-6.xml
  Validate XML: https://dl-ssl.google.com/android/repository/addon-6.xml
  Parse XML:    https://dl-ssl.google.com/android/repository/addon-6.xml
  Fetching URL: https://dl-ssl.google.com/glass/gdk/addon.xml
  Validate XML: https://dl-ssl.google.com/glass/gdk/addon.xml
  Parse XML:    https://dl-ssl.google.com/glass/gdk/addon.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/extras/intel/addon.xml
  Validate XML: https://dl-ssl.google.com/android/repository/extras/intel/addon.xml
  Parse XML:    https://dl-ssl.google.com/android/repository/extras/intel/addon.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/sys-img/android/sys-img.xml
  Validate XML: https://dl-ssl.google.com/android/repository/sys-img/android/sys-img.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/sys-img/android-wear/sys-img.xml
  Validate XML: https://dl-ssl.google.com/android/repository/sys-img/android-wear/sys-img.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/sys-img/android-tv/sys-img.xml
  Validate XML: https://dl-ssl.google.com/android/repository/sys-img/android-tv/sys-img.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/sys-img/x86/addon-x86.xml
  Validate XML: https://dl-ssl.google.com/android/repository/sys-img/x86/addon-x86.xml
Refresh Sources:
  Fetching URL: https://dl-ssl.google.com/android/repository/addon.xml
  Validate XML: https://dl-ssl.google.com/android/repository/addon.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/sys-img/android/sys-img.xml
  Validate XML: https://dl-ssl.google.com/android/repository/sys-img/android/sys-img.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/sys-img/android-wear/sys-img.xml
  Validate XML: https://dl-ssl.google.com/android/repository/sys-img/android-wear/sys-img.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/sys-img/android-tv/sys-img.xml
  Validate XML: https://dl-ssl.google.com/android/repository/sys-img/android-tv/sys-img.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/sys-img/x86/addon-x86.xml
  Validate XML: https://dl-ssl.google.com/android/repository/sys-img/x86/addon-x86.xml
Refresh Sources:
  Fetching URL: https://dl-ssl.google.com/android/repository/addon.xml
  Validate XML: https://dl-ssl.google.com/android/repository/addon.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/sys-img/android/sys-img.xml
  Validate XML: https://dl-ssl.google.com/android/repository/sys-img/android/sys-img.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/sys-img/android-wear/sys-img.xml
  Validate XML: https://dl-ssl.google.com/android/repository/sys-img/android-wear/sys-img.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/sys-img/android-tv/sys-img.xml
  Validate XML: https://dl-ssl.google.com/android/repository/sys-img/android-tv/sys-img.xml
  Fetching URL: https://dl-ssl.google.com/android/repository/sys-img/x86/addon-x86.xml
  Validate XML: https://dl-ssl.google.com/android/repository/sys-img/x86/addon-x86.xml
Packages available for installation or update: 15
   1- Android SDK Tools, revision 23
   2- Android SDK Platform-tools, revision 20
   3- Documentation for Android SDK, API 19, revision 2
   4- SDK Platform Android 4.4.2, API 19, revision 3
   5- Samples for SDK API 19, revision 5
   6- Samples for SDK API 18, revision 1
   7- Samples for SDK API 17, revision 1
   8- Samples for SDK API 16, revision 1
   9- Samples for SDK API 15, revision 2
  10- Samples for SDK API 14, revision 2
  11- Samples for SDK API 13, revision 1
  12- Samples for SDK API 12, revision 1
  13- Samples for SDK API 11, revision 1
  14- Samples for SDK API 10, revision 1
  15- Glass Development Kit Preview, Android API 19, revision 8



[3] AVD(Virtual Device) Manager
prayag@prayag: /BirthdayForestGap$ $ANDROID_HOME/tools/android avd




$ANDROID_HOME//tools/android list targets | grep android-23

[3.1] Start any of the AVDs from the list already created. Same thing can be achieved through 
prayag@prayag: /BirthdayForestGap$ $ANDROID_HOME/tools/emulator -avd AVD -netspeed full -netdelay none
emulator: emulator window was out of view and was recentered



[3.2] List AVD confs
$ ls -l ~/.android/avd/
total 40
drwxrwxr-x 2 prayag prayag 4096 May 14  2013 avd.avd
-rw-rw-r-- 1 prayag prayag   72 Jul 20  2012 avd.ini
drwxrwxr-x 2 prayag prayag 4096 Jun 23  2013 FroyoVD.avd
-rw-rw-r-- 1 prayag prayag   60 Apr 28  2013 FroyoVD.ini
drwxrwxr-x 2 prayag prayag 4096 Sep 28  2012 Google31TV.avd
-rw-rw-r-- 1 prayag prayag   84 Aug  9  2012 Google31TV.ini
drwxrwxr-x 2 prayag prayag 4096 Apr 21  2013 HC32.avd
-rw-rw-r-- 1 prayag prayag   58 Sep 11  2012 HC32.ini
drwxrwxr-x 2 prayag prayag 4096 Dec 31 23:50 Kitkat.avd
-rw-rw-r-- 1 prayag prayag  112 Dec 25 23:59 Kitkat.ini

[4] ant build

REFERENCES
[1] How do I launch the Android emulator from the command line?,
http://stackoverflow.com/a/4974695/432903

[2] http://developer.android.com/tools/building/building-cmdline.html