Skip to main content

Posts

Showing posts from May, 2020

How to run Bash commands in parallel and wait before all commands finished

In this article i will explain how you can run commands in parallel and make sure you wait until all commands and have finished and then move forward.

Say you have a script which downloads few files or yu have to compile different maven project(independent of each other) or something else which can run in parallel and you have got a good machine which can run these tasks in parallel so that overall you can run the full task in lowest time.
For this you can use back ground task and wait from unix.
When you add & to any command that command runs in background
What is wait command? wait is a built-in command of Linux that waits for completing any running process. wait command is used with a particular process id or job id. When multiple processes are running in the shell then only the process id of the last command will be known by the current shell. If wait command is executed this time, then it will be applied for the last command.

If no process id or job id is given with wait comm…

How to install docker on Ubuntu 20.04 LTS

In this article i will explain how you can install Docker on UBUNTU 20.04 LTS
To learn more about docker please visit official site

First make sure you will have installed all the updates

sudo apt update -y Then install docker by running simple command sudo apt install docker.io Then make sure docker starts after computer restarts sudo systemctl enable --now docker At this opint root user is able to run docker command, but any other user wont be able to use docker. To give permission to any user or current user run # Current user sudo usermod -aG docker $USER #Any other user sudo usermod -aG docker SOMEUSERNAME Now you can check docker version docker version Restart your compuer so that any user added to added group can run docker command. Now you should be able to run any docker image, here is a simple example docker run hello-world Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker t…

Static and final, when and how to use

Usually when some one ask a simple question when you will make variable or function as static, a simple answer comes to mind

Variables : when i want to make single instance of that variable shared across all objects of this class. Good answer :) Functions : When i want to access a function of class without creating its object. Good answer :) Currently not talking about classes  Both are good answer but not complete. There are more things static do behind the screen then things mentioned above.

Static fields will not be serialised.

Check Following code

Class ClassWithStaticFunction{ public void doSomething(){ ...     doSomethingMore(); ... } private void doSomethingMore(){ ... ... } }
In above example a developer can say i can't make it better performance unless you tell me what these functions are doing(... lines), but that's incorrect you can make it performant without knowing about what goes inside it.

 When a function is made static as a developer you have made sure that…

How to git without finger print confirmation

In this article i will explain how you can run git clone command on a machine without having to accept sh key finger prints manually.

Lets you want to write a script to initialise a developer machine, which require you to git clone various projects from gitlab or github or any other git repo.

First time you run a git clone command, it will ask you if you accept the signature and it need to be part of automated script, its not nice thing to have.


Here is the solution.

First you download the git host's keythen create its finger printthen check this finger print against known valid finge rprintIf its good then move downloaded ssh key to ~/.ssh/known_hosts fileelse throw error



ssh-keyscan github.com >> githubKey ssh-keyscan gitlab.com >> gitlabKey export githubfinger=$(ssh-keygen -lf githubKey) export gitlabfinger=$(ssh-keygen -lf gitlabKey) echo $githubfinger echo $gitlabfinger if [[ $githubfinger == *"nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8"* ]]; the…