VMware Cloud Community
Soulassassin
Contributor
Contributor
Jump to solution

Script to string together vmkping commands and return results in txt file

Hi guys, hope you are all doing very well?

Does anyone know if there is a way that I can put this together?

What I am trying to do here is to bypass the tedious process of pinging every configured IP for my iSCSI targets across each VMK from each host.

So basically I want some advice from you guys so that I can basically get this into a script.

vmkping -I vmk1 10.0.0.10

vmkping -I vmk2 10.0.0.10

vmkping -I vmk3 10.0.0.10

vmkping -I vmk4 10.0.0.10

vmkping -I vmk5 10.0.0.10

vmkping -I vmk6 10.0.0.10

vmkping -I vmk7 10.0.0.10

vmkping -I vmk8 10.0.0.10

vmkping -I vmk9 10.0.0.10

vmkping -I vmk1 10.0.0.11

vmkping -I vmk2 10.0.0.11

vmkping -I vmk3 10.0.0.11

vmkping -I vmk4 10.0.0.11

vmkping -I vmk5 10.0.0.11

vmkping -I vmk6 10.0.0.11

vmkping -I vmk7 10.0.0.11

vmkping -I vmk8 10.0.0.11

vmkping -I vmk9 10.0.0.11

vmkping -I vmk1 10.0.0.12

vmkping -I vmk2 10.0.0.12

vmkping -I vmk3 10.0.0.12

vmkping -I vmk4 10.0.0.12

vmkping -I vmk5 10.0.0.12

vmkping -I vmk6 10.0.0.12

vmkping -I vmk7 10.0.0.12

vmkping -I vmk8 10.0.0.12

vmkping -I vmk9 10.0.0.12

etc.... etc....

Doing this on every host is proving to take longer that I would like it to take. Since we are busy troubleshooting an issue on our switches where some of the VMK ports are unable to communicate to the targets. Is there anyway we can script this?

Please guys, I am desperate here.

Kind regards,

Johan

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
stevemonson
Contributor
Contributor
Jump to solution

You can do this from a bash script.

Here's a working script that gets a list of all vmkernel ports then pings each IP supplied in a list.txt file on every vmkernel port. The results are printed to screen but to get the results to file just pipe the output.

Here's an example:

"sh vmkping.sh >/tmp/vmkpingResults.log"

#!/bin/bash

# Program name: vmkpingall.sh

# Store a list.txt file with each Target Storage IP on a separate line

#----EXAMPLE list.txt---------

#172.16.191.50

#172.16.192.50

#-----------------------------

#Print out the date and the hostname

date

hostname

#get a list of all vmk ports on the host

for vmknum in $(esxcli network ip interface list |grep vmk | grep -v Name:)

do

#Trim leading white space

vmkCompare="${vmknum##*( )}"

#Trim trailing whitespace

vmkCompare="${vmkCompare%%*( )}"

        # Exclude vmk0, becuase we don't use our management vmkernel port for vmotion traffic so pings are expected to fail on vmk0

        if [ "$vmkCompare" != "vmk0" ] ; then

                cat /path-to-script/list.txt |  while read output

                do

                        #use vmkping command in selected vmk port '-I' to ping the target IP addresses

                        vmkping -I "$vmknum" -c 1 "$output" > /dev/null

                        if [ $? -eq 0 ]; then

                                echo "node $output is up on $vmknum "

                        else

                                echo "node $output is down on $vmknum "

                        fi

                done

        fi

done

View solution in original post

3 Replies
rdtechie
Enthusiast
Enthusiast
Jump to solution

Hi Johan, maybe this script useful for you: Remote VMKping and Other Network Utilities « James Elliott's VMware Blog

PowerShell Addict. Make it so lover.
Reply
0 Kudos
stevemonson
Contributor
Contributor
Jump to solution

You can do this from a bash script.

Here's a working script that gets a list of all vmkernel ports then pings each IP supplied in a list.txt file on every vmkernel port. The results are printed to screen but to get the results to file just pipe the output.

Here's an example:

"sh vmkping.sh >/tmp/vmkpingResults.log"

#!/bin/bash

# Program name: vmkpingall.sh

# Store a list.txt file with each Target Storage IP on a separate line

#----EXAMPLE list.txt---------

#172.16.191.50

#172.16.192.50

#-----------------------------

#Print out the date and the hostname

date

hostname

#get a list of all vmk ports on the host

for vmknum in $(esxcli network ip interface list |grep vmk | grep -v Name:)

do

#Trim leading white space

vmkCompare="${vmknum##*( )}"

#Trim trailing whitespace

vmkCompare="${vmkCompare%%*( )}"

        # Exclude vmk0, becuase we don't use our management vmkernel port for vmotion traffic so pings are expected to fail on vmk0

        if [ "$vmkCompare" != "vmk0" ] ; then

                cat /path-to-script/list.txt |  while read output

                do

                        #use vmkping command in selected vmk port '-I' to ping the target IP addresses

                        vmkping -I "$vmknum" -c 1 "$output" > /dev/null

                        if [ $? -eq 0 ]; then

                                echo "node $output is up on $vmknum "

                        else

                                echo "node $output is down on $vmknum "

                        fi

                done

        fi

done

Soulassassin
Contributor
Contributor
Jump to solution

Thanks Steve. Works like a charm!

Reply
0 Kudos