Listing 1 Bash script: get_info
#!/bin/bash
JMPSERVER=jump.myisp.net
PORT=9012
LOGINSEQ=('secret1' 'myadm' 'secret2')
CMDS=('date' 'info' 'uptime' 'quit')
while read device
do
# In background, run an ssh tunnel
ssh -N ${JMPSERVER} -L ${PORT}:${device}:23 &
sleep 2
for n in 1
do
# login sequence
typeset -i i=0
while test ${i} -lt ${#LOGINSEQ[*]}
do
echo ${LOGINSEQ[${i}]}
i+=1
sleep 1
done
# run commands
typeset -i j=0
while test ${j} -lt ${#CMDS[*]}
do
echo ${CMDS[${j}]}
j+=1
sleep 1
done
done | telnet localhost ${PORT}
kill $! # terminate the ssh background process
done
|