Top 10 Scripting Languages in DevOps | List of Best Scripting Languages

top-10-scripting-languages-in-devops
This is the time of DevOps in software industry and DevOps uses different different languages for deployment automation and for software development. This is the reason if you are a DevOps professional and want to be succeed in DevOps role than command on scripting languages is must. But, one can not be a master of all. Right? Therefore, In this article I am going to share a list of top 10 scripting languages which will be useful for your DevOps journey.
But before that let’s have a quick look on Scripting language.
Scripting languages are programming languages that communicate and integrate with other programming languages. In other words, scripting languages controlls interactive programs operations by giving it sequence of work to execute by one command at a time.
Now, let’s look on to the list of top 10 scripting languages

1. Microsoft PowerShell

Microsoft PowerShell

Microsoft powershell or powershell is belongs to Microsoft and an open source cross platform scripting language. If you have application infrastructure with windows than powershell is must for you. This scripting language is designed for system admins.
2. Puppet

Puppet

Puppet is a configuration management tool and it has it’s own declarative language to describe system configuration. It runs on Linux, Unix-like and also on Windows. This one is available under Apache 2.7.0 and General Pubic license.  Puppet uses a custom declarative language, it just needs to specify ‘what’ action needs to be performed on the resources.
3. Chef

Chef

Chef is basically known as configuration management which belongs to chef is also a scripting language which is designed by David Morgan. It makes programs look like cooking any food.
4. Bash

Bash

Bash is basically a command language which is available in open source and written by Brian Fox in the year 1989. It can read scripts and Bash is the most commonly used Unix shell. Bash supports Linux, Windows and Mac OS.
5. Ruby

Ruby

Ruby is amongst one of the best programming language but it is also a scripting language which is written by Yukihiro Matsumoto in the year 1995. Ruby supports cross platforms and it is available under GPL and BSD license. It supports multiple programming paradigms, including functional, object-oriented, and imperative.
6. Ansible

Ansible

Ansible is known as configuration management and application deployment tool but it is also amongst top scripting languages. This language is belongs to Ansible Inc. and written by their community members. It supports Linux, Unix-like and Windows operating system.
7. Perl

Perl

Perl is a scripting language which is used for advanced web applications development. Perl is written by Larry Wall and first released in the year 1987. Perl supports cross platforms. Perl is available under general public license.
8. Python

Python

Python is also amongst the top scripting languages which is used for high level of programming. It was first released in the year 1991 by Guido van Rossum. python is available under Python Software Foundation License. It’s supports Cross-platform.
9. Go language

Go language

Go scripting language belongs to the Internet giant Google. This scripting language is written by Robert Griesemer, Rob Pike and Ken Thompson and it was released in the year 2009. It supports  Linux, macOS, FreeBSD, NetBSD, OpenBSD, Windows, Plan 9, DragonFly BSD and Solaris operating systems. It is available in open source.
10. Groovy

Groovy

Groovy can be used as a scripting language and it is also consider as a top scripting languages for DevOps professionals. It was designed by James Strachan and developed by Guillaume Laforge, Jochen Theodorou, Paul King and Cedric Champeau. It was first released in the year 2003 and available under Apache license. It supports Java platform.
Do you agree with this list? If not than feel free to respond in the comment box with your own take on the most essential scripting languages. One more thing, I would like to add here, if you need help to learn all these scripting languages and DevOps courses than scmGalaxy can help you in this. scmGalaxy is a community of DevOps professionals who are well experienced in this domain.
Tagged : / / / / / / / / / / / / / / / / / / /

How to get bash or ssh into a running container in background mode?

bash-or-ssh-into-a-running-container
How to get bash or ssh into a running container in background mode?
Step 1: First of all, try to find your active container by running
# docker ps
or
# docker ps -a
Step 2: If the container is not running,
# docker start your_id
Step 3: If we use attach we can use only one instance of shell.
# sudo docker attach 665b4a1e17b6 #by ID
or
# sudo docker attach loving_heisenberg #by Name
If we want open new terminal with new instance of container’s shell, we just need run the following:
# sudo docker exec -i -t 2e56ad1705b1 /bin/bash #by ID
or
# sudo docker exec -i -t loving_heisenberg /bin/bash #by Name
# root@665b4a1e17b6:/#
Step 4: To exit bash without leaving bash running in a rogue process
# exit
Notes:
A reminder for boot2docker users: remove sudo
If you are using docker in Linux, you will have to use sudo along with docker commands.
You should try not to run commands as sudo, rather add your user to the docker group and just run normally.
Tagged : / / / / / / / /

Shell Scripting (Bash) Training | Bash/Shell Scripting Course

shell-bash-scripting-training

Introduction

  • Introduction
  • Why Shell Scripting?
  • Linux Internal
  • What to Expect From This Course?
  • Prerequisites

Git fundamental

  • Introduction of git
  • Git setup
  • Basic operations in git
  • Github
  • Summary

A First Look At Shell Scripts

  • Introduction
  • Creating A Shell Script
  • Demo: A Note-Taking Script
  • Calling The Script
  • The Shebang
  • Naming Your Script
  • Demo: The type Command
  • Summary

Variables

  • Introduction
  • Demo: Variables
  • Using Variables in A Script
  • Using Variables: Good Habits
  • Reading Input
  • Debugging your Script
  • Summary

If, Then, Else

  • Introduction
  • Demo: The If Statement
  • The If Statement
  • Return codes
  • The Conditional Expression
  • Demo: The Conditional Expression
  • The Conditional Expression 2
  • Arithmetic Tests
  • Demo: Arithmetic Tests
  • The If Statement Revisited
  • And, Or, Not
  • Summary

Input and Output

  • Introduction
  • Output: echo and printf
  • Input: read revisited
  • Standard Streams and Redirection
  • Demo: Redirection
  • Summary

Control Flow

  • Introduction
  • While and Until
  • The Classic For Statement
  • The C-Style For Statement
  • Break and Continue
  • The Case Statement
  • && and ||
  • Summary

Variables 2

  • Introduction
  • Integer Variables
  • Arithmetic Expressions
  • Arithmetic Expressions 2
  • Read-only Variables
  • Exporting Variables
  • Arrays
  • Summary

Handling Script Parameters

  • Introduction
  • Special Variables
  • Shift
  • Getopts
  • Getopts: Handling Errors
  • Summary

Shell Functions

  • Introduction
  • Shell Functions
  • Shell Functions 2
  • Functions: Demo
  • Some Miscellaneous Remarks
  • Summary

Fun with Strings

  • Introduction
  • Removing Part Of A String
  • Search and Replace
  • Setting A Default Value
  • Conditional Expression Patterns
  • Regular Expressions in The Conditional Expression
  • End of Options
  • Summary

Many Ways to Run Your Script

  • Introduction
  • Running your Code
  • Nohup and The Background
  • Exec
  • At and Cron
  • Set and Shopt
  • Summary
Tagged : / / / / / / / / / / / / / / / / / / / / / / / / /

BASH aliases for GIT | Bash Git Aliases Reference

bash-aliases-for-git

BASH aliases for GIT

Following BASH aliases can be used in ~/.BASHRC

alias g = “git status”
alias ga = “git add”
alias gaa = “git add .”
alias gc = “git commit -m”
alias gca = “git commit -am”
alias gb = “git branch”
alias gbd = “git branch -d”
alias gco = “git checkout”
alias gcob = “git checkout -b”
alias gm = “git merge”
alias gr = “git rebase”
alias gl = “git log”
alias gs = “git show”
alias gd = “git diff”
alias gbl = “git blame”
alias gps = “git push”
alias gpl = “git pull”

Tagged : / / / / / / / /

Understand Shell Script Parameters – Reference

shell-script-parameters

A parameter is an entity that stores values. It can be a name, a number or some special characters.

Bash shell provides two kind of parameters.

Positional Parameter and Special Parameter

Bash Positional Parameter – $0, $1, $2 ..

Positional parameters are the arguments given to your scripts when it is invoked. It could be from $1 to $N. When N consists of more than a single digit, it must be enclosed in a braces like ${N}.

The variable $0 is the basename of the program as it was called.

The following example gets two arguments and provides arithmetic operations result between those two integers.

First, create the arithmetic.sh shell script as shown below.

$ cat arithmetic.sh

#!/bin/bash

echo -e “\$1=$1”

echo -e “\$2=$2”


let add=$1+$2

let sub=$1-$2

let mul=$1*$2

let div=$1/$2

echo -e “Addition=$add\nSubtraction=$sub\nMultiplication=$mul\nDivision=$div\n”

Next, execute the arithmetic.sh with proper parameters as shown below.

$ ./arithmetic.sh 12 10

$1=12

$2=10

Addition=22

Subtraction=2

Multiplication=120

Division=1

In the above output $1 has the value 12, and $2 has 10.

Shell built-in ‘let’ allows arithmetic operation to be performed on shell variables. The above script does the arithmetic operations such as addition, subtraction, multiplication and division on the given parameters.

Set / Unset Bash Positional Parameters

The built in set command is used to set and unset the positional parameter.

First, create the positional.sh shell script as shown below.

$ cat positional.sh

#!/bin/bash

# From command line

echo -e “Basename=$0”

echo -e “\$1=$1”

echo -e “\$2=$2”

echo -e “\$3=$3”

# From Set builtin

set First Second Third

echo -e “\$1=$1”

echo -e “\$2=$2”

echo -e “\$3=$3”

# Store positional parameters with -(hyphen)

set – -f -s -t

echo -e “\$1=$1”

echo -e “\$2=$2”

echo -e “\$3=$3”

# Unset positional parameter

set —

echo -e “\$1=$1”

echo -e “\$2=$2”

echo -e “\$3=$3”

The above script prints the command line arguments first, then set command sets the positional parameter explicitly. Set with the – refers end of options, all following arguments are positional parameter even they can begin with ‘-’. Set with ‘–’ without any other arguments unset all the positional parameters.

Next, execute the positional.sh as shown below.

$ ./positional.sh

Basename=positional.sh

$1=12

$2=10

$3=

$1=First

$2=Second

$3=Third

$1=-f

$2=-s

$3=-t

$1=

$2=

$3=

Use Bash $* and $@ to Expand Positional Parameters

This example shows the value available in $* and $@.

First, create the expan.sh as shown below.

$ cat expan.sh

#!/bin/bash

export IFS=’-‘

cnt=1

# Printing the data available in $*

echo “Values of \”\$*\”:”

for arg in “$*”

do

echo “Arg #$cnt= $arg”

let “cnt+=1”

done

cnt=1

# Printing the data available in $@

echo “Values of \”\$@\”:”

for arg in “$@”

do

echo “Arg #$cnt= $arg”

let “cnt+=1”

done

Next, execute the expan.sh as shown below to see how $* and $@ works.

$ ./expan.sh “This is” 2 3

Values of “$*”:

Arg #1= This is-2-3

Values of “$@”:

Arg #1= This is

Arg #2= 2

Arg #3= 3

· The above script exported the value of IFS (Internal Field Separator) with the ‘-’.

· There are three parameter passed to the script expan.sh $1=”This is”,$2=”2″ and $3=”3″.

· When printing the each value of special parameter “$*”, it gives only one value which is the whole positional parameter delimited by IFS.

· Whereas “$@” gives you each parameter as a separate word.

Use $# to Count Positional Parameters

$# is the special parameter in bash which gives you the number of positional parameter in decimal.

First, create the arithmetic.sh as shown below.

$ cat arithmetic.sh

#!/bin/bash

if [ $# -lt 2 ]

then

echo “Usage: $0 arg1 arg2”

exit

fi

echo -e “\$1=$1”

echo -e “\$2=$2”

let add=$1+$2

let sub=$1-$2

let mul=$1*$2

let div=$1/$2

echo -e “Addition=$add\nSubtraction=$sub\nMultiplication=$mul\nDivision=$div\n”

If the number of positional parameters is less than 2, it will throw the usage information as shown below,

$ ./arithemetic.sh 10

Usage: ./arithemetic.sh arg1 arg2

Process related Parameters – $$ and $!

The special parameter $$ will give the process ID of the shell. $! gives you the process id of the most recently executed background process.

The following script prints the process id of the shell and last execute background process ID.

$ cat proc.sh

#!/bin/bash

echo -e “Process ID=$$”

sleep 1000 &

echo -e “Background Process ID=$!”

Now, execute the above script, and check the process id which its printing.

$ ./proc.sh

Process ID=9502

Background Process ID=9503

$ ps

PID TTY TIME CMD

5970 pts/1 00:00:00 bash

9503 pts/1 00:00:00 sleep

9504 pts/1 00:00:00 ps

$

Other Bash Special Parameters – $?, $-, $_

· $? Gives the exit status of the most recently executed command.

· $- Options set using set builtin command

· $_ Gives the last argument to the previous command. At the shell startup, it gives the absolute filename of the shell script being executed.

$ cat others.sh

#!/bin/bash

echo -e “$_”; ## Absolute name of the file which is being executed

/usr/local/bin/dbhome # execute the command.

#check the exit status of dbhome

if [ “$?” -ne “0” ]; then

echo “Sorry, Command execution failed !”

fi

echo -e “$-“; #Set options – hB

echo -e $_ # Last argument of the previous command.

In the above script, the last echo statement “echo -e $_” ($ underscore) also prints hB which is the value of last argument of the previous command. So $_ will give the value after expansion

$ ./others.sh

./others.sh

/home/oracle

Sorry, Command execution failed !

hB

hB

Tagged : / / / / / / / / / / / / / / / /