Wednesday, August 3, 2016

Find My Phone : The best hidden feature of Android

Find My Phone

1.    Open any internet browser
2.    Go to Google search
3.    Search for “find my phone”.
               [[ Don’t forgot to sign-in to google before you search. ]]


4.    Now Click On “Ring” to locate your phone, if it is somewhere near to you but unable to find.

If you lost your phone, you can locate your phone and can select “Enable Lock & Erase” option.


5.     Access your phone from another phone
you can have the access to your own phone another phone by login as guest user in your friend’s phone.

** Major drawback : This option will not work if the phone is not connected to internet.

-Thank you

Monday, July 25, 2016

Shell Script :generating random numbers

Generating random numbers is bit easier as compare to generating random numbers in other languages.

To generate a random number in shell script use below command
$RANDOM

The above command is case sensitive and hence $random will not give you desire result.

Generating  random number with in a range
lr=100 # lower range
ur=600 # upper range
r=`expr $ur - $lr`
echo "The random number of `expr $RANDOM % $r + $lr`"


-Thank you

Sunday, July 24, 2016

Shell Script : Reading a file Line by Line in shell script

Reading the file using loop statement

File name : job.txt
File Content :
   Data
   RAM:256 MB
   Bandwidth:1 gbps

Command 1:
        
              while read line
              do
                echo $line
              done <job.txt 
Output :
 
   Data
   RAM:256 MB
   Bandwidth:1 gbps


Command 2:
        
              for line in $(cat job.txt)
              do
                echo $line
              done <job.txt 
Output :
  
   Data
   RAM:256
   MB
   Bandwidth:1
   gbps

Saturday, July 23, 2016

Shell Script : Creating and Running a shell script file

OS : Ubuntu 14.04
Steps are as follows:

Step 1: Open Terminal by pressing ctrl+alt+T

Step 2: Use any editor to create a shell script file. 
       
         Sample 1:  sudo gedit firstShell.sh 
         Sample 2:  sudo vim firstShell.sh 
         Sample 3:  sudo vi firstShell.sh 

Step 3: Enter the following line
        
          echo "I am from firstShell.sh file !!!"  
 
Now save the file according to the editor you are using.
Step 4: Modify the attribute of the file as executable file
        

         Sample:  sudo chmod +x firstShell.sh  
 
Step 5: Now RUN the shell script file by entering following command in the terminal

         ./firstShell.sh

VirtualBox from command line

Different VirtualBox operation from command line :

To know the Version of the VirtualBox
Command :
                vboxmanage -v
Sample Output:


To show the list of VMs:
Command :
                vboxmanage list vms
Sample Output :


To show the list of currently running VMs:
Command :
                vboxmanage list runningvms


To display the details of a specific VM
Command :
                vboxmanage showvminfo VM1
Sample Output :
* "VM1" is the name the VM
* The screenshot of Sample Output is NOT containing all the information.


To create a Virtual machine :
Command 1:
                vboxmanage createvm --name "VM2"
Sample Output :

After creating the VM, follow the below step to showed up in the "Oracle VM virtualBox manager"
Step 1- Select "Machine" menu.
Step 2- Click "Add" option.
Step 3- Browse to path of setting file
Step 4- Double click on "VM2.vbox" file
Now you can see the detail of VM2 as follows:


Command 2:
                vboxmanage createvm --name "VM2" --register
* --register option will register the VM with VirtualBox and hence this will enable us to display the recently created VM in "Oracle VM virtualbox manager" window.


To modify the settings of an already created VM
Command 1: [To modify the memory]
                vboxmanage modifyvm VM2 --memory 512
Command 2: [To assign the OS type]
                vboxmanage modify VM2 --ostype Ubuntu
Command 3:[To attach the SATA controller ]
                vboxmanage storagectl VM3 --name SATA -add sata --controller IntelAhci --bootable on
Command 4: [To attach the SATA (.vdi file)]
                vboxmanage storageattach  VM3 --storagestl SATA --port 0 --device 0 --type hdd --medium <path of the .vdi file>


To clone a Virtual machine :
Command 1 : 
                vboxmanage clonevm VM1_CPU --name VM1_IO --register
Sample Output :



 To control the network bandwidth 
Command :
                1. vboxmanage bandwidthctl VM1 add Limit --type network --limit 100k
                2. vboxmanage bandwidthctl VM1 set Limit --type network --limit 100k











Tuesday, July 5, 2016

Latex : Part - 6 : Watermark in Latex


Text as Watermark

To Display the text as watermark in Latex insert the following content in .tex file before "\begin{document}" statement.
 Place your content in "\SetWatermarkText{}" command.
For above command below is the output

Figure as Watermark

coming soon....


Saturday, July 2, 2016

Latex : Part - 5 : Writing Algorithm/Pseudocode in Latex


Requirement :
  • You should have updated Latex repository
  • Any editor for writing latex code, such as TexStudio, Notepad++, Sublime Text etc.
Step:
  • In order to write a pseudo code or an algorithm in Latex , you must use algorithm package at the beginning of the document 
  • Below are some examples, you can follow.
Example - 1
Output
Figure-1.a : Example 1 output
Source Code 



Figure-1.b : Source code for the output given in Figure-1.a


Note:
  1. Please insert \; at end of each statement.
  2. "\qquad" command is used to give a horizontal tab at the beginning of the line.
Example - 2
   Note:

  • Use algorithmic package 
                          
Output

Figure 2.a: Example 2

Source Code 




Figure 2.b :  Source code for output in Figure 2.a 
Example - 3
Note:
  • Use following packages
Output





Source Code




Tuesday, June 21, 2016

Configure openssh-server in ubuntu.

ssh enables one computer to communicate to another computer over a secure encrypted channel. In order to establish the environment we need both ssh server on the target computer and ssh client on the computer from where we intend to access the target computer.

In this post, we'll see how to install ssh-server on the target computer (server)



Requirement:
     OS on target computer : Ubuntu 14.04 or later
     Target computer must be connected to internet to get the required software packages.

Installation:


        1. open the terminal by pressing

 ctrl + Alt + t  


        2. Now enter the following command to install ssh-server

sudo apt-get install openssh-server

              Use sudo for if you are not in root, else you can avoid using

Configuring openssh-server:

        1. Configuration file : To configure, we need to modify sshd_config file present inside /etc/ssh/

        2. Backup : Before configuring, please take a backup of the configuration by entering following command in the terminal

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_backup

        3. Open configuration file by entering following command.
sudo nano /etc/ssh/sshd_config 
             
        4.  Configure ssh port number. Find the line
 port 22  
             now change the port number according to your requirement.
        5.  Deny root login: Find the line
 PermitRootLogin without-password  

             Now change the line to
 PermitRootLogin no  

        6.  Allow specific user : At the end of the file add following line.

 AllowUsers user1 user2  

             this will restrict all other users with username other then user1 and user2

Above are the basic configuration to start playing with ssh.
Don't forget to restart the ssh service after every modification. To restart the ssh server, use following command
sudo service ssh restart
   
For more information, just comment below.


-Thank you

Friday, June 17, 2016

Accessing Linux (Ubuntu) account remotely through SSH

Its easy to access your linux account exactly sitting in-front of the personal computer. But how about accessing your linux account from another place which is far from the personal computer. Follow below steps to access your linux account.
Definition
Target Computer: the computer to which you want to connect or we can say your personal computer. <refer figure 1>
Source Computer: The computer from which you want to access your target computer. <refer figure 1>
Figure 1: Accessing target Computer from Source computer



Requirement:
    1. Target computer must be turned ON

    2. Target computer must have internet connection
        or
        Source computer must be accessible from target computer through LAN, WAN or in anyway.

    3. Software requirement for Source Computer :
        Putty: which can be downloaded from below link
        For windows: http://tartarus.org/~simon/putty-snapshots/x86/putty.exe
        For Mac & Ubuntu : Use “Terminal” . // No third party software is required
       
    4. Software requirement for Target Computer :
        openssh-server : openssh-server must be install on your personal computer to accept the connection from another computer present remotely

Steps: 

For Target Computer
  1. We assume that Ubuntu is installed on target computer
  2. Install openssh-server by executing below command in the “Terminal”
sudo apt-get install openssh-server
      3. follow below link to configure the openssh-server
               http://blogchinmaya.blogspot.com/2016/06/configure-openssh-server-in-ubuntu.html

For Source Computer

For Windows

    S1: download and install Putty for windows from below link.
    S2: Open putty
Figure 2: Putty in Windows


    S3: Here, it needs 2 main information.
         S3.1: Enter the address of the target computer
         S3.2: Enter the ssh port number on target computer
    S4: Select "SSH" radion option
    S5: now click on "Open" button to connect to the target computer
Figure 3: Putty Login window 
     S6: Now enter your username and password

For Mac & Linux (ubuntu)

    S1: open Terminal (FOR MAC)
         S1.1 : press <command> + <Space> 
         S1.2 : search for “terminal”

Figure 4: Open terminal in mac
    S1: Open Terminal (for Ubuntu)
         You can open the trminal by pressing < ctrl > + < alt > + < t > 

    S2: gather following information
           S2.1: Account name and password in target computer
           S2.2: address of the target address
           S2.3: port, on which ssh server is running on the target computer
    S3: enter following command in terminal
ssh <username>@<address> -p <port number>
           Now enter your password
e.g.


Thats all, its done. Now you can browse the your filesystem using common linux command.

Wednesday, May 20, 2015

GO Programming Language : Executing external system command using "Go" language

Prerequisite : you must have basic knowledge of how to execute a programming in Go language.
How execute first hello world program.

In following section, we will discuss, how to execute an external program. My goal is, instead of executing a command in terminal, I want to execute using Go programming language.

Source Code:
package main
import (
        "bytes"
        "fmt"
        "log"
        "os/exec"
        "strings"
)

func main() {
        cmd := exec.Command("docker","ps","-a")
        cmd.Stdin = strings.NewReader("")
        var out bytes.Buffer
        cmd.Stdout = &out
        err := cmd.Run()
        if err != nil {
                log.Fatal(err)
        }
        fmt.Printf("Output \n",out.String())
}

Output:
Ahh... I got a long list of output as expected.


Description:
In the source, I was trying to execute the following command
docker ps -a
For this, I pass the above command as argument to function "command" as different strings.
When I tried to pass whole command (i.e. docker ps -a) as a single string, it produce an error saying "exec: "docker ps -a": executable file not found in $PATH exit status 1". This means the first argument is the name of the executable file and in order to execute the command it tries to search the file mentioned in first string in function "exec.Command()". Since in my case the actual executable file name is "docker", this couldn't execute the "docker ps -a" command.
So, every word in the command (or the external program we want to execute) must be provided as different string to "exec.Command()".

That's all for now.


-Enjoy