The following ping script is running just fine in both script form and interactive shell
ping-only.sh
date
for i in 10.1.1.1 10.1.1.3 10.4.1.13
do echo -e "\nIP: $i"
ping -c 1 $i | grep from
done
However, when I run the SSH shell script, it just stuck at the first host
ssh-get-banner-only.sh
date
for i in 10.1.1.1 10.1.1.3 10.4.1.13
do echo -e "\nIP: $i"
timeout 1 ssh $i
done
Sample output
user@APIC> ./ssh-get-banner-only.sh
Mon May 6 04:43:24 UTC 2019
IP: 10.1.1.1
###############################################################
# Authorized access only! #
###############################################################
It work just fine when I paste the same code manually to the shell
user@APIC> date
Mon May 6 04:36:33 UTC 2019
user@APIC> for i in 10.1.1.1 10.1.1.3 10.4.1.13
> do echo -e "\nIP: $i"
> timeout 1 ssh $i
> done
IP: 10.1.1.1
###############################################################
# Authorized access only! #
###############################################################
Password:
IP: 10.1.1.3
###############################################################
# Authorized access only! #
###############################################################
Password:
IP: 10.4.1.13
###############################################################
# Authorized access only! #
###############################################################
Password:
user@APIC>
echo "$SHELL"
and then add a shebang to the first line of your script.user@APIC:~> echo $SHELL /bin/bash user@APIC:~>
Doesn't matter whether the shebang is there or not. Still getting the same output