Archives for Scripting - Page 3
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…
Python Script to Access Team Foundation Server (TFS) Rest API
I was working in a project where I have to access Team Foundation Server (TFS) Rest API in Python script. It was little bit tricky job to access TFS REST API from python 2 . Specially for beginners like me :) . I was facing issue to authenticate TFS REST…
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"…
Get the List of Files and Directories Recursively in Linux
Simple bash Script to get the list of files and directories inside the specified path Sometimes we want to get the list of files and directories recursively, but it is tedious to navigate each directory to check all the files. Here are the simple commands which will help you to…
Get File MIME Type in Python
Get file MIME type in Python You can get file mime type in python by using python-magic library. You can install python-magic using PIP. $ pip install python-magic To find mime type, import magic library and pass file path into () >>> import magic >>> ("path/", mime=True) 'application/pdf' If you…
Rename all Files in the Directory
Here is the simple shell script to rename all files in the folder with increasing number. In below example I am going to rename all jpg image with increasing number. #!/bin/bash a=1 for i in *.jpg; do new=$(printf "%" "$a") mv -- "$i" "$new" let a=a+1 done Output: Few more…
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…

