Search This Blog

18 February, 2016

Android Showing IP address and Route Table

For checking the IP address and Routing Table in Android using command line mode in the linux console is below. For this you need to root the device or it should be engineering build which engineers use for development.

To Show IP Address, MAC address and Interface Status
Type  netcfg  or ip addr

To See The Routing Table
cat /proc/net/route   OR   ip route show

To show DNS IP Addresss
getprop net.dns1
getprop net.dns2

net.dns1 for the Primary DNS and net.dns2 for the Secondary DNS

For changing the DNS IP Address:
setprop net.dns1 111.111.111.111
setprop net.dns2 222.222.222.222




18 September, 2015

end of line sequences in different OS

end of line sequences
Windows end of line sequence:  \r\n
Unix end of line sequence: \n
Mac end of line sequence: \r

11 September, 2015

Recovering moved or deleted files in Linux

I was developing one C program which I spend 1 day writing with around  500 lines of code in Ubuntu 12.04 

for compiling in GCC, I used the below command

# gcc server.c -o server.c

instead of giving gcc server.c -o server 

now my whole source code was replaced with the binary file :( :(  , a simple mistake which caused my whole source code got deleted or replaced. I had a habit of pressing for auto completing the file names. 

After searching for some time googling, i got a solution which worked for me and saved my 9 hours of work.

I got the help form this below link
http://www.cyberciti.biz/tips/linuxunix-recover-deleted-files.html

repeating what is said there and which i tried and worked for me

in the console with sudo permission
sudo grep -a -B[size before] -A[size after] 'filename or unique content' /dev/[your_partition] > file.txt

-i : Ignore case distinctions in both the PATTERN and the input files i.e. match both uppercase and lowercase character.
-a : Process a binary file as if it were text
-B Print number lines/size of leading context before matching lines.
-A: Print number lines/size of trailing context after matching lines.


my command was
sudo grep -a -B10 -A1000 'UNIQUE_SERVER_IP' /dev/sda1 > file.txt

UNIQUE_SERVER_IP was the #define i did it in my source code. After the command is over, open the file.txt with vi or any text editor and search for the string 'UNIQUE_SERVER_IP'. you should find your source code around the string, copy paste and save to the required file name

I got the my source code back in some time.



09 September, 2015

counting number of lines in c and include files in Linux

After writing source code in Linux, if you want to count the number of lines in .c and .h files

find . -name '*.c' -o -name '*.h' | xargs wc -l

Converting IP Address from string in dot format to 32 bit integer

C program to convert IPv4 address from String formatted in dat notation like "10.0.0.1" to a 32 bit integer in Linux

#include<stdio.h>
#include <arpa/inet.h>

main()
{

    uint32_t ip;
    struct in_addr ip_addr;

    ip = inet_addr("10.0.0.1");
    printf("IP Integer: %d\n", ip);
    ip_addr.s_addr = ip;
    printf("The IP address is: %s\n", inet_ntoa(ip_addr));

}

06 September, 2015

Cassandra cqlsh queries

Below are the commands useful for querying the cassandra database .
These are executed by logging into the Cassandra command line interface(CLI), CQLSH

1) showing the keyspaces(or databases )

describe keyspaces;

2)
Showing Tables in the keyspace(or database)

2.1. use <keyspace_name>;

2.2 describe tables;  this will show the tables in the keyspace(database)

3) Creating Index to an Exiting table with column

 CREATE INDEX tripid_idx ON table_4(tripid);


4) To show TABLE info using cqlsh
        DESC TABLE table_1 ;

06 August, 2015

Turning off expandtab in VIM for editing makefile

if you had set the .vimrc to change the tab to spaces for C programming, it will be difficult to edit or create makefiles,

 i had trouble creating makefile , i was getting the below error

Makefile:18: *** missing separator.  Stop.


after googled little and  found the  solution, edit the .vimrc file like below



let _curfile = expand("%:t")
if _curfile =~ "Makefile" || _curfile =~ "makefile" || _curfile =~ ".*\.mk"
set noexpandtab
else
set expandtab
set tabstop=4
set shiftwidth=4
endif

tmux enabling mouse interaction

Add the below line to the ~/.tmux.conf setw -g mouse on save the file and exit from the tmux shell, you should be able to use your mouse to ...