Reputation: 1
this is my code in shell expect.
#!/usr/bin/expect -f
array set routers { 0 "192.168.1.1" 1 "127.0.0.1"}
array set password { 0 "56343451" 1 "123456789" }
set size 2
set COUNT 10
for {set i 0} {$i < $size} {incr i 1} {
set count "[ping -c $COUNT $routers($i) | grep 'received' | awk -F',' '{ print \$2 }' | awk '{ print \$1 }']"
if { $count <= 3 } {
spawn ssh root@$routers($i)
expect { "no)?" { send "yes\r"; exp_continue }
password: { send $password($i)"\r"; exp_continue}
interact
}
}
}
I want to get output receive from ping to $count. When I try to run this is occurs " ": no such file or directory "
Upvotes: 0
Views: 125
Reputation: 16428
You have to brace the awk
expressions.
% set COUNT 3
3
% set router 135.xxx.xx.xxx
% exec /bin/ping -c $COUNT $router | grep "received" | awk -F "," {{print $2}} | awk {{print $1}}
3
%
Upvotes: 1