0

for below code i want to check if the IP is up via ping and if ip is up run below code eles check next ip from hosts.txt

Edit 2: FYI ill be running script from windows machine

Edit 3:I managed to write incorporate a line,now with this script is pinging all the IP's mentioned in hosts.txt file but fails if any IP is down. What is required: I want script to go to the next IP if any IP is down.

#!/usr/bin/expect -f

#This Script will provide critical info which are required during troubleshooting

#Setting up Variables
set timeout 15                                                                                                                                 
set fid [open ./hosts.txt r]
set contents [read -nonewline $fid]
close $fid

#Grabbing Password to be used in script further
stty -echo
send_user -- "Enter the Password: "
expect_user -re "(.*)\n"
send_user "\n"
stty echo
set pass $expect_out(1,string)
foreach host [split $contents "\n"] {

    set timeout 5
    spawn ping $host
    expect  {
    "Reply" {puts "$host Is Up"}
    "Request" {puts "$host Is Down"}
        }

GauravG
  • 19
  • 7
  • ` set fid [open ./hosts.txt r] set contents [read -nonewline $fid] close $fid #Grabbing Password to be used in script further stty -echo send_user -- "Enter the Password: " expect_user -re "(.*)\n" send_user "\n" stty echo set pass $expect_out(1,string) foreach host [split $contents "\n"] { set timeout 5 spawn ping $host expect { "Reply" {puts "$host Is Up"} "Request" {puts "$host Is Down"} } ` I have reached till above code and it is working for all ip which are up.I need help in figuring out how to go to next IP if any IP is down @glenn – GauravG Jul 28 '20 at 08:15
  • Please edit changes to your question instead of posting them as a comment. Comments can't have line breaks that are crucial both for syntax and for readability. – Esa Jokinen Jul 29 '20 at 05:51

0 Answers0