Tag archives for shell - Page 2
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…
Shell Scripting Tutorial for Beginners
Shell Scripting Tutorial for Beginners I am sharing few beginner shell scripting reference that we need in day-to-day tasks. Local Variable in Shell Script We can create local variables in shell script by using the keyword local. #!/bin/bash HELLO=Hello function helloWorld { local HELLO=World echo $HELLO } echo $HELLO helloWorld…
Deleting Lines Containing Specific string from multiple files
Deleting Lines Containing Specific string from multiple files Deleting Lines Containing Specific string from multiple files recursively Syntax: grep -Rl "STRING" /directory/path/ | xargs sed -i "/STRING/d" Example: Below example delete lines containing @license tag from src/main/php directory all files recursively grep -Rl "@license" src/main/php | xargs sed -i "/@license/d"…
Run Mysql Query from Command Line
Shell script to run mysql query from command line without login into mysql command prompt. You can use these shell script for quickly execution of MySQL query from a Linux Shell. Method 1: #!/bin/bash #Script to run mysql query from command line #Db Connection. DB_USER='root' DB_PASSWD='mypwd' DB_NAME='mydb' #Prepare sql query QUERY='select *…
Start mysql service if not running
Here is the simple shell script check the MySQL service status, if MySQL service is not running then start MySQL service. #!/bin/bash SERVICE='mysql' if ps ax | grep -v grep | grep $SERVICE > /dev/null then echo "$SERVICE service is running." else echo "$SERVICE is not running" service mysqld start…

