Archives for Linux
How to get process ID of background process?
I usually prefer to execute process in background so that we don't need to worry if terminal got killed due to timeout or accidently. However, what if you want to kill the process then definitely you will you PID of that process to kill it. You may be interested to…
How to check certificate validity in Linux?
This article help you to check certificate expiry date from Linux command line using openssl utility. Check SSL certificate expiration date Syntax: openssl x509 -enddate -noout -in <certificate name> openssl x509 -enddate -noout -in openssl x509 -enddate -noout -in
Could not resolve host: mirrorlist.centos.org Centos 7
I have installed Centos 7 in Vmware WorkStation. I tried to install few new packages using yum install. However, I was getting error "Could not resolve host: Centos 7" [root@localhost ~]# yum install dos2unix Loaded plugins: fastestmirror Could not retrieve mirrorlist ;arch=x86_64&repo=os&infra=stock error was 14: curl#6 - "Could not resolve…
How to Split String with a Delimiter in Shell Script
Split String with a Delimiter in Shell Script You can use Internal Field Separator (IFS) variable in shell script to split string into array. When we set IFS variable then the assignment to IFS only takes place to that single command's environment to read. It then parses the input according…
How to validate date format in shell script
How to validate date format in shell script There are multiple ways you can validate date format in shell script. You can compare date format with regular expression or you can use inbuilt date command to check given date format is valid or not. I am sharing a simple date…
Loop through a date range in Shell Script
Loop through a date range in Shell Script Here is a simple shell script which accept two date value as argument and perform desired action for date value in #!/usr/bin/bash start=$1 end=$2 start=$(date -d $start +%Y%m%d) end=$(date -d $end +%Y%m%d) while ] do echo $start start=$(date -d"$start + 1 day"…
Pass date as mandatory arguments in bash script
Pass date as mandatory arguments in bash script I came across a use case where I have to write a shell script to perform some action on two date ranges. The first argument would start date and the second argument as end date. To validate missing argument we can also…
How to define multiline string variable in shell?
How to define multiline string variable in shell? In your bash/shell scripting experience you may face scenario where you need to define multi line string variable. Here is multiple ways to define multi line string variable in shell. Method 1: Combine Multiline with \n like below and echo with -e…
How to run multiple bash scripts in parallel
If you working as a Linux administrator or as a DevOps engineer then you might get a use case where you need to run multiple bash scripts in parallel without waiting to finish execution of previous script. Let me show you possible ways to achieve this in bash script For…
Get the last ten business days in a Unix shell script
Shell script to get the last 10 weekdays and run some task for each date over an element array. #!/usr/bin/bash n=10 today=$(date +'%Y-%m-%d') for ((d=1; n>0; d++)) do # Adjust this next line to get the date format you require, +'%Y%m%d' date=$(date --date "$today -$d day") nday=$(date --date "$today -$d…






