Sunday, August 19, 2018

Using expect to run "nc -w 3 -z $IP 22" command on macOS but get long waiting timeout

I using linux expect command to execute "nc -w 3 -z $IP 22" command on macOS.

I expected timeout after 3 seconds but I got 1m 15s (Due to "nc" command can setting timeout via "-w" argument).

I run the same code at other linux(Debian 7.8, ubuntu 14.04) machines are normally.

Who can tell me why I got the different result between linux and macOS ?

Following content is my source code:

#!/usr/bin/expect -f

set DUT_IP "192.168.1.2"

if {0!=[catch {exec sh -c "nc -w 3 -z $DUT_IP 22 && echo \$?"}]} {
  send_user "Cannot connect to DUT $DUT_IP\n"
  exit -1
} else {
  puts "IP exist"
}

No comments:

Post a Comment