11 April 2014

Cowsay

Fun with Cowsay
As per unix manual, Cowsay is a configurable speaking/thinking cow. Cowsay is fun and bring relief when working with commands become long.
whatis cowsay
cowsay (6) - configurable speaking/thinking cow (and a bit more)

# try out this few commands
cowsay hello
cowthink hello
fortune | cowsay
fortune | cowthink
# Using others figures:
cowsay -f /usr/share/cowsay/cows/elephant.cow hello
fortune | cowsay -f /usr/share/cowsay/cows/elephant.cow
-f  is a file argument. it point to a cow file. and
/usr/share/cowsay/cows/elephant.cow  is the cow file.

cowsay -f /usr/share/cowsay/cows/vader.cow "The Empire strikes back"


# Here are few customised alias to make it easier to use cowsay. append the code below into .bashrc .

.bashrc
#cowsay alias
cowfolder=/usr/share/cowsay/cows

alias aptsay='cowsay -f $cowfolder/apt.cow'
alias beavis.zensay='cowsay -f $cowfolder/beavis.zen.cow'
alias bongsay='cowsay -f $cowfolder/bong.cow'
alias bud-frogssay='cowsay -f $cowfolder/bud-frogs.cow'
alias bunnysay='cowsay -f $cowfolder/bunny.cow'
alias calvinsay='cowsay -f $cowfolder/calvin.cow'
alias cheesesay='cowsay -f $cowfolder/cheese.cow'
alias cocksay='cowsay -f $cowfolder/cock.cow'
alias cowersay='cowsay -f $cowfolder/cower.cow'
alias daemonsay='cowsay -f $cowfolder/daemon.cow'
alias defaultsay='cowsay -f $cowfolder/default.cow'
alias dragon-andsay='cowsay -f $cowfolder/dragon-and.cow'
alias dragonsay='cowsay -f $cowfolder/dragon.cow'
alias ducksay='cowsay -f $cowfolder/duck.cow'
alias elephantsay='cowsay -f $cowfolder/elephant.cow'
alias elephant-in-snakesay='cowsay -f $cowfolder/elephant-in-snake.cow'
alias eyessay='cowsay -f $cowfolder/eyes.cow'
alias flaming-sheepsay='cowsay -f $cowfolder/flaming-sheep.cow'
alias ghostbusterssay='cowsay -f $cowfolder/ghostbusters.cow'
alias gnusay='cowsay -f $cowfolder/gnu.cow'
alias head-insay='cowsay -f $cowfolder/head-in.cow'
alias hellokittysay='cowsay -f $cowfolder/hellokitty.cow'
alias kisssay='cowsay -f $cowfolder/kiss.cow'
alias kittysay='cowsay -f $cowfolder/kitty.cow'
alias koalasay='cowsay -f $cowfolder/koala.cow'
alias koshsay='cowsay -f $cowfolder/kosh.cow'
alias luke-koalasay='cowsay -f $cowfolder/luke-koala.cow'
alias mech-andsay='cowsay -f $cowfolder/mech-and.cow'
alias meowsay='cowsay -f $cowfolder/meow.cow'
alias milksay='cowsay -f $cowfolder/milk.cow'
alias moofasasay='cowsay -f $cowfolder/moofasa.cow'
alias moosesay='cowsay -f $cowfolder/moose.cow'
alias mutilatedsay='cowsay -f $cowfolder/mutilated.cow'
alias ponysay='cowsay -f $cowfolder/pony.cow'
alias pony-smallersay='cowsay -f $cowfolder/pony-smaller.cow'
alias rensay='cowsay -f $cowfolder/ren.cow'
alias sheepsay='cowsay -f $cowfolder/sheep.cow'
alias skeletonsay='cowsay -f $cowfolder/skeleton.cow'
alias snowmansay='cowsay -f $cowfolder/snowman.cow'
alias sodomized-sheepsay='cowsay -f $cowfolder/sodomized-sheep.cow'
alias stegosaurussay='cowsay -f $cowfolder/stegosaurus.cow'
alias stimpysay='cowsay -f $cowfolder/stimpy.cow'
alias susesay='cowsay -f $cowfolder/suse.cow'
alias three-eyessay='cowsay -f $cowfolder/three-eyes.cow'
alias turkeysay='cowsay -f $cowfolder/turkey.cow'
alias turtlesay='cowsay -f $cowfolder/turtle.cow'
alias tuxsay='cowsay -f $cowfolder/tux.cow'
alias uniponysay='cowsay -f $cowfolder/unipony.cow'
alias unipony-smallersay='cowsay -f $cowfolder/unipony-smaller.cow'
alias vadersay='cowsay -f $cowfolder/vader.cow'
alias vader-koalasay='cowsay -f $cowfolder/vader-koala.cow'
alias wwwsay='cowsay -f $cowfolder/www.cow'

alias aptthink='cowthink -f $cowfolder/apt.cow'
alias beavis.zenthink='cowthink -f $cowfolder/beavis.zen.cow'
alias bongthink='cowthink -f $cowfolder/bong.cow'
alias bud-frogsthink='cowthink -f $cowfolder/bud-frogs.cow'
alias bunnythink='cowthink -f $cowfolder/bunny.cow'
alias calvinthink='cowthink -f $cowfolder/calvin.cow'
alias cheesethink='cowthink -f $cowfolder/cheese.cow'
alias cockthink='cowthink -f $cowfolder/cock.cow'
alias cowerthink='cowthink -f $cowfolder/cower.cow'
alias daemonthink='cowthink -f $cowfolder/daemon.cow'
alias defaultthink='cowthink -f $cowfolder/default.cow'
alias dragon-andthink='cowthink -f $cowfolder/dragon-and.cow'
alias dragonthink='cowthink -f $cowfolder/dragon.cow'
alias duckthink='cowthink -f $cowfolder/duck.cow'
alias elephantthink='cowthink -f $cowfolder/elephant.cow'
alias elephant-in-snakethink='cowthink -f $cowfolder/elephant-in-snake.cow' alias eyesthink='cowthink -f $cowfolder/eyes.cow'
alias flaming-sheepthink='cowthink -f $cowfolder/flaming-sheep.cow'
alias ghostbustersthink='cowthink -f $cowfolder/ghostbusters.cow'
alias gnuthink='cowthink -f $cowfolder/gnu.cow'
alias head-inthink='cowthink -f $cowfolder/head-in.cow'
alias hellokittythink='cowthink -f $cowfolder/hellokitty.cow'
alias kissthink='cowthink -f $cowfolder/kiss.cow'
alias kittythink='cowthink -f $cowfolder/kitty.cow'
alias koalathink='cowthink -f $cowfolder/koala.cow'
alias koshthink='cowthink -f $cowfolder/kosh.cow'
alias luke-koalathink='cowthink -f $cowfolder/luke-koala.cow'
alias mech-andthink='cowthink -f $cowfolder/mech-and.cow'
alias meowthink='cowthink -f $cowfolder/meow.cow'
alias milkthink='cowthink -f $cowfolder/milk.cow'
alias moofasathink='cowthink -f $cowfolder/moofasa.cow'
alias moosethink='cowthink -f $cowfolder/moose.cow'
alias mutilatedthink='cowthink -f $cowfolder/mutilated.cow'
alias ponythink='cowthink -f $cowfolder/pony.cow'
alias pony-smallerthink='cowthink -f $cowfolder/pony-smaller.cow'
alias renthink='cowthink -f $cowfolder/ren.cow'
alias sheepthink='cowthink -f $cowfolder/sheep.cow'
alias skeletonthink='cowthink -f $cowfolder/skeleton.cow'
alias snowmanthink='cowthink -f $cowfolder/snowman.cow'
alias sodomized-sheepthink='cowthink -f $cowfolder/sodomized-sheep.cow'
alias stegosaurusthink='cowthink -f $cowfolder/stegosaurus.cow'
alias stimpythink='cowthink -f $cowfolder/stimpy.cow'
alias susethink='cowthink -f $cowfolder/suse.cow'
alias three-eyesthink='cowthink -f $cowfolder/three-eyes.cow'
alias turkeythink='cowthink -f $cowfolder/turkey.cow'
alias turtlethink='cowthink -f $cowfolder/turtle.cow'
alias tuxthink='cowthink -f $cowfolder/tux.cow'
alias uniponythink='cowthink -f $cowfolder/unipony.cow'
alias unipony-smallerthink='cowthink -f $cowfolder/unipony-smaller.cow'
alias vaderthink='cowthink -f $cowfolder/vader.cow'
alias vader-koalathink='cowthink -f $cowfolder/vader-koala.cow'
alias wwwthink='cowthink -f $cowfolder/www.cow'


# Open terminal and try them:
aptsay hello world.
ducksay hello.
elephantsay "i am round."
elephantthink "am i round!"
duckthink "Where are all the fish?"
tuxsay welcome
fortune | tuxsay
fortune | tuxthink
date | cowsay
whatis cowsay | cowthink
echo "i'm `whoami`" | tuxsay
bunnysay hello.


Time Counter

Time Counter

Time Counter

Create a time counter using Shell scripting.

# Create a file  time.txt  in home folder (any folder is ok). put '0' (zero) in it as second (starting value of time).

time.txt
0


# Create a  time.sh  script (in the same folder) and put this code in it.
#!/bin/sh
#file: time.sh
#description: keep track of time spend on computer.

file=time.txt

if [[ -f $file ]]; then
old_time=$( cat $file ) && new_time=$[ $old_time + 60 ] && echo $new_time > $file ;
else
echo '0' > $file ;
fi;
This script will take stored time value from  time.txt  and add 60 seconds to it when run.
So if the current stored time value is '0' (zero), it will add 60 seconds to it. and so on.


# Now we will run this script with crontab. Open Terminal and edit crontab:
crontab -e

..and add this line to the bottom of the file:
* * * * * /bin/bash ~/time.sh
This will make the  time.sh  to run and update  time.txt  simulteneously every minute.


# put this code in .bashrc file (found in home folder). with this we can check the time on terminal..
counter() {
second=$( cat ~/time.txt ) ;
day=$[ $second/86400 ] ;
hour_remain=$[ $second%86400 ] ;
hour=$[ $hour_remain/3600 ] ;
minute_remain=$[ $second%3600 ] ;
minute=$[ $minute_remain/60 ] ;

echo $day days $hour hours $minute minutes since 2014 April 12th.

}


# Open Terminal and enter counter:
0 days 0 hours 44 minutes since 2014 April 12th.


12 March 2014

Hidden power of Android

android

Hidden Power of android.

Every android phone comes with a Busybox , which provides several unix tools. (Android use a Linux kernel. ). unfortunately android does not provide a shell or command interpreter. like xterm in Debian/Ubuntu. user will have to install them manually. few of it are. • Below are some useful command found in android:

cal displays a calendar and the date of Easter
dd convert and copy a file
df , du report file system disk space usage
dos2unix , unix2dos convert file from one format to another.
ftpget , ftpput , tftp File transfer client & server.
httpd A barebone web server.
ifconfig configure a network interface
ip show / manipulate routing, devices, policy routing and tunnels.
md5sum , sha1sum , sha256sum , sha512sum compute and check MD5 , SHA1SUM , SHA256SUM , SHA512SUM message digest
nc The swiff army knife of network mapping.
netstat Display network connections, routing, tunnel etc.
ping , ping6 send ICMP ECHO_REQUEST to network hosts
ps Display process
sh , ash Shell or Command interpreter
sqlite3 A command line interface for SQLite version 3
telnet , telnetd A Telnet client & server.
traceroute , traceroute6 Trace the route to HOST
top Display top process
touch change file timestamps
udhcpc , udhcpd DHCP client & server.
uname Get system or kernel information
uptime Tell how long the system has been running.
vi Text Editor
wget The non-interactive network downloader.
who show who is logged on
whois client for the whois directory service


Other commonly use command:
awk , basename , id , hostname , clear , cat , date , diff , dirname , dmesg , echo , dnsdomainname , env , false , find , hostid , head , grep , less , ln , ls , mkdir , logname , more , mv , pwd , sleep , sort , rm , rmdir , sed , renice , reset , tail , tee , test , true , uniq , which , whoami , wc , yes .

Here are few example:

ping -c 5 google.com
sqlite3 foo.db
Web Server:
busybox httpd -h /mnt/sdcard/www/ -p 8888
Download Manager:
busybox wget -c www.example.com/map.png
Telnet Server:
busybox telnetd
busybox telnet 127.0.0.1
busybox whois www.google.com
busybox uname -a
busybox top -d 2
dd if=pic1.jpg of=pic2.jpg
busybox cal 2014
busybox netstat -tun


22 February 2014

Installing ADB in GNU/Linux

adb

Making ADB work in Linux (Debian/Ubuntu)

  1. Install Android Debug Bridge for GNU/Linux.

    • for Debian & DEB packages:
    sudo apt-get install android-tools-adb

    • for Redhat & RPM packages:
    sudo yum install android-tools-adb


  2. Connect android phone.
    lsusb
    Bus 001 Device 008: ID 058f:6366 Alcor Micro Corp. Android
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Find the corresponding line for your android phone.
    The Vendor & Product ID will be in XXXX:XXXX format. In our example the ID's is 058f:6366 .
    058f = VendorID.
    6366 = ProductID.


  3. Create Rules.
    sudo gedit /etc/udev/rules.d/51-android.rules
       you can use vi, nano, pico or any text editor in place of gedit.

    append the code to the file.
    SUBSYSTEM=="usb", ATTR{idVendor}=="058f", ATTR{idProduct}=="6366", MODE="0666", GROUP="plugdev"


  4. Create adb file in home ( ~ ) folder.
    mkdir ~/.android
    ( if not already created. )
    touch ~/.android/adb_usb.ini
    echo '0x6366' >> ~/.android/adb_usb.ini


  5. Restart udev.
    sudo service udev restart
    adb kill-server
    adb start-server


  6. Reconnect the Phone.
    You may need to disconnect and reconnect the phone again. and wait for a couple of minute to get it detected.
    adb devices
    List of devices attached
    19761202 device
    45024745 device




# The short way.

Copy this code into the terminal (replaces id's) and run it.

echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="6366", ATTR{idProduct}=="058f", MODE="0666", GROUP="plugdev"' | sudo tee -a /etc/udev/rules.d/51-android.rules && mkdir ~/.android/ && touch ~/.android/adb_usb.ini && echo '0x6366' >> ~/.android/adb_usb.ini && sudo service udev restart && adb kill-server && adb start-server && adb devices
Replace the VendorID & ProductID with the one you got....