Created
November 13, 2024 17:50
-
-
Save albal/acf744bbab6e7974cbdb93e6bab4472a to your computer and use it in GitHub Desktop.
get-ips.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Define an array of remote host IPs | |
| hosts=("10.199.251.11" "10.199.251.12" "10.199.251.13") | |
| # Loop through each host | |
| for host in "${hosts[@]}"; do | |
| echo "Connecting to $host..." | |
| # Execute the command remotely to get the IP address and subnet mask of ens6f0 | |
| address_with_mask=$(ssh user@$host "ip -f inet addr show ens6f0 | grep -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+/\d+'") | |
| # Display the result | |
| if [ -n "$address_with_mask" ]; then | |
| echo "IP address with subnet mask of ens6f0 on $host is: $address_with_mask" | |
| else | |
| echo "Could not retrieve IP address and subnet mask for ens6f0 on $host." | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment