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