Calling a bash script with parameters | Demo to get IP address of any domain

Calling a bash script with parameters | Demo to get IP address of any domain

. 1 min read

Originally posted at https://blog.mypad.in/calling-a-bash-script-with-parameters-demo-to-get-ip-address-of-any-domain/

In this post, lets look at solving a recurring task of having to launch bash scripts with custom parameters.

I'll demonstrate this with a sample problem of Getting the IP address of any domain

There are various ways of solving this problem, but my persistent preference is to use the all powerful terminal and keep things simple and minimalistic.

Parameters to a script can be simple passed like below:

bash './shell/custom-shell-script-get-domain.sh' yahoo.com

The script for ./shell/custom-shell-script-get-domain.sh is as follows:

#!/bin/bash

URL=$1
echo "URL is: $URL"

IP=$(dig +short $URL | head -1)
echo "IP of $URL is: $IP"

Calling-a-bash-script-with-parameters-1

Get IPs of multiple domains

Getting the IP of domains is pretty simple too!

The script that loops through the domains called custom-shell-script-get-domains-loop.sh is as follows:

#!/bin/bash

# execute using:
# bash './shell/custom-shell-script-get-domains-loop.sh' 'google.com' 'yahoo.com' 'ft.com' 'wsj.com'

for domain in "$@"
do
  URL=$domain
  echo "URL is: $URL"

  IP=$(dig +short $URL | head -1)
  echo "IP of $URL is: $IP"
done

Execution is pretty simple again!

bash './shell/custom-shell-script-get-domains-loop.sh' 'google.com' 'yahoo.com' 'ft.com' 'wsj.com'

get-ips-of-passed-domains-using-a-bash-script-loop


Tags

AWS Analytics Antifragile Apache Spark Apple Apps Arbitrage Automation Awesome BBMP Bangalore Black Swan Bonds Boonex Bootstrap Brokerage Charges CFPB CMS CSS Calypso Camelot Capital Markets Charts Chirp Choropleth Chrome Code Igniter Collections Containerization Converters Cycling DalalBeat Data Analytics Data Journalism Data Mining Data Munging Data Privacy Data Science Databases Debt Design Design Stock DesignStock Diet Django Docker Document Processing Dropbox Electron Electronics Entertainment Entrepreneurship Exercise FFMPEG Facebook Finance Fire TV Stick Fitness Forerunner From-The-News Fun Futures Gaana Garmin General Geocoding Getting Started Ghost Google APIs GraphicsMagick HHVM HTTPS Hackathon Hacks Hardware Health House Keeping Housing IBM BlueMix IBrokers IPinfo Ideas Image Conversion Image Processing Infographics Interactive Brokers Internet Investing IoT Legal Lets Encrypt Mac Machine Learning Mailbox app Mapbox Markdown Marketing Meteor Mockups MongoDB Mortgages Movies Music MyPad MySQL Nativefier Nature Netflix Newsletters Nginx Node.js Notes OCR OSX Open Source OpenCPU Options PDF PHP Pebble Peloton Personal Photography Picture Platforms Plex Portable Apps Productivity Property Tax PyroCMS Quantitative Finance R-Project Random Raspberry Pi Research Resources Reticulate Robot S3 SQLite STT Scraping Security Server Shell Shiny Side Project Sikuli Speech Recognition Spider Pro Spinning Spotify Startup Resources Startups Strategy Sublime Text System Monitoring Tax Terminal Tips To Do Tools Torrent Trading Trends Troubleshooting USElection2016 Ubuntu Unix Valuations Video Conversion Visualization Wagtail Wearables Weekend Fun WhatsApp Wordpress anaconda annie bash catalina cv2 daily coding dailycoding data.table debugging devtools downloader e-Signatures ggplot git go google maps hat-tip iOS iPad iPhone iTunes javascript jupyter logging macos numpy opencv optionality plotly python rstats videos youtube