Showing posts with label shell scripting tutorials. Show all posts
Showing posts with label shell scripting tutorials. Show all posts

Friday, September 14, 2018

AWK Command - In an Easy way




Awk stands for Aho Weinberger and Kernighan. Awk is a scripting language to process and analyze files.
Some of the features of Awk are given below :
  • Awk actually work on data files.
  • Awk can generate formatted output.
  • Awk support different regular expressions.
  • Awk allows different features of traditional programming language like conditions, operators, loop , functions and so on.
Syntax of Awk command
  1. awk 'program' input_file
The simplest program is the sequence of actions. Each action has either pattern or no pattern. Each action is enclosed with braces. We explain with a typical file named input.txt that contains name , age and height like this :
  1. Mehedi 01 WDE 25000
  2. Arafat 02 WDE 27000
  3. Baki 03 SDE 30000
  4. Mahbub 04 ADE 29000
  5. Nazmul 05 SDE 24000
If action has pattern , then matches that pattern with files line by line until end of file and print the matches lines. Example :
  1. awk '$4>=25000 {print $1, $2 }' in.txt
Output are given below
  1. Mehedi 01
  2. Arafat 02
  3. Baki 03
  4. Mahbub 04
Otherwise, action is performed for all lines of input file.
  1. awk '{print $1, $2 }' in.txt
Output are given below :
  1. Mehedi 01
  2. Arafat 02
  3. Baki 03
  4. Mahbub 04
  5. Nazmul 05
We can also write program that has only pattern and action is missing. For these programs the matched line is printed. But it is not a good practice to write only pattern without action.
  1. awk '/WDE/' in.txt
Output :
  1. Mehedi 01 WDE 25000
  2. Arafat 02 WDE 27000
Some points about printing :
  • At the time of printing the all field of input lines we just write print.
  1. awk '{print }' in.txt
  • Otherwise we write print and particular column number with dollar sign like $1. For more column we obviously use comma as a separator.
  1. awk '{print $1, $2 }' in.txt

Sunday, September 9, 2018

Why you need ssh ... Ever wondered ?


Many of us have got up the answer as "ssh is secure shell" . But when it  comes to  the realistic question - why ssh is required ? you get stuck with different answers. Don't worry you will get to know till the end to this blog.




 Let me  make it very simple  for you  ~

Ssh is a protocol (meaning - a set of rules) which helps you to  transfer the data between systems/machines in a very secure manner without any security breach.It has replaced at least  4 main protocols - telnet,ftp,vnc (partly), vpn (partly).With the encrypted keys mechanism,ssh helps you to securely login to other machines. These keys are public and private keys .


Now lets come back to the why part , why we need it ? So.. the outstanding capability of encrypting and transferring the data makes SSH  - the developers or administrators  first choice to use.You need to connect to other machine ! - use ssh , but how ?  check it ..  




      1. Generate a  key using ssh-keygen command , this command will                                  generate a public and  private key .
                                 

                       


     2. Copy the public key to all machines that you want to ssh or transfer the                    data:

        [hdp@nn1 ~]$ cat id_rsa.pub | ssh  username@machine 'cat >>                                            .ssh/authorized_keys'


              For-example :   username is 'hdp' and machine is 192.168.1.10, So your                                                  command will be  :
                 
                cat id_rsa.pub | ssh  hdp@192.168.1.10 'cat >> .ssh/authorized_keys'

            

  •  id_rsa.pub  - Thus is a  public key file which is encrypted , it  will be copied to other   machines , this key is a available in .ssh location 
  •  id.rsa - This  is a private  encrypted key file 
  • authorized_keys - This File  is copied to the machines to which you want to connect or transfer the data securely . 


      3.   Now , last step is ssh to the machine you want to connect : 


So , you can check in 3rd step that on ssh 192.168.1.10 (machine host-name)  , it is successfully login us to the another machine . 





AWK Command - In an Easy way

Awk stands for Aho Weinberger and Kernighan. Awk is a scripting language to process and analyze files. Some of the features of Awk ...