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 . 





Thursday, September 6, 2018

Interesting facts about ~/Linux

Some facts about Linux
  • In 2000 Steve Jobs Offered Linus Torvalds a job at APPLE on the condition that he should stop the development of Linux, But Linus refused to join and continued developing his product.
  • Microsoft was very much not impressed by its open source systemswhich were criticized badly but later it was sponsored by Microsoft itself.
  • Android is the highest using operating system on the planet with 2 billion people but Android runs on Linux.
  • Linux is very late that it released after three years of it's announced date.
  • Linux is the only operating system named after its founder Linus Torvalds
  • Linux has 20,323,379 lines of code which was pretty small in the version of the kernel.
  • Linux first name was “FreaX” which was a combination of “free”, “freak” and “Unix”)
  • Google, Intel, Huawei, Samsung, Red Hat, Canonical and Facebookare among the top contributors to Linux kernel development in recent years.
  • 9 out of top 10 public cloud infrastructures run on Linux.
  • IBM chose Linux for what is expected to be the world’s most powerful supercomputer, Sequoia.
  • All major closed source Operating Systems track user information while Linux distros generally don't, which means better user Security and Privacy is assured.

Saturday, September 1, 2018

Best practice for writing shell scripts




Add this snippet at the top of your scripts to get a log of what they did, every time they run. This can help when writing new scripts or debugging something that fails after the fact. 

I've used this a lot when building scripts to auto-configure hosts after booting.  Capturing the output of these scripts can be awkward and it's valuable data to  analyze what happened on a failed build, even days later.

Friday, August 31, 2018

Chmod 777


Why Not chmod 777?

Because.
But seriously, what are you trying to achieve? It is probably due to a misunderstanding of the Unix/Linux filesystem permissions model. The question is common (hence this page), but the answer is always the same: If you assess what your requirements are, you are very likely to find that the existing permissions model will work for you, as it has done for many different projects over the decades. The chances that your project is significantly different from all other Unix/Linux projects is very low.
Most Unix and Linux systems generally allow appropriate access to files; /bin/ls can be executed by anybody to list files; your /home/USERNAME/.bashrc is readable by you, but your /home/USERNAME is typically accessible only to yourself, and as a result of that, anything under that location (including your .bashrc) is also unavailable to other users of the system.
This is a deliberate part of the design. It has been in use for over 40 years (at time of writing, in 2017), and it has worked very well for very many successful projects, and although it is quite a simple system, there are a few nuanced ways in which it can be used to suit your particular needs, if they are particularly specialised.

Group Membership

The easist way to approch sharing files between users, is to put them in a common group. If you are in the group, you can access the files.

SetGID Bit

The "SetGID Bit" on a directory means that any files created in that directory will be owned by the group that owns the directory, regardless of who created them. It is marked as an "s" in place of the "x" where the Group permissions go: drwxr-sr-x. It is set by the command: "chmod g+s <directory-name>".

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 ...