#!/bin/bash progname=${0##*/} die() { printf >&2 '%s ERROR: %s\n' "$progname" "$*" exit 1 } read -rsp 'Password: ' pass >&2 printf >&2 '\r\e[K' exec {zmin}<> <(:) exec {zmout}< <( script -f /dev/null -c ' ssh -oPubkeyAcceptedAlgorithms=+ssh-rsa \ -oHostKeyAlgorithms=+ssh-dss admin@zmodem ' 2>&1 <&$zmin ) IFS= read -d : -u $zmout -t 3 line || die "Can't connect." echo >&$zmin "$pass" IFS= read -d \> -u $zmout -t 3 _ || die "No prompt line." # Zyxel prompt: ZySH> getPppStat() { echo >&$zmin 'ifconfig | grep "ppp\|RX b"' while read -u $zmout -t .2 line;do case $line in RX* | ifconfig* ) ;; ppp* ) IFS=': ' read -ru $zmout -t 1 _ _ rx _ _ _ _ tx _ break ;; * ) echo $line;; esac done IFS= read -d \> -u $zmout -t 3 _ || die "No prompt line." } start=${EPOCHREALTIME/.} getPppStat elap=00000$(( ${EPOCHREALTIME/.} - start )) printf '%7.4f %s %s\n' ${elap::-6}.${elap: -6} ${rx@A} ${tx@A} orx=${rx} otx=${tx} sleep 2 start2=${EPOCHREALTIME/.} getPppStat elap=00000$(( ${EPOCHREALTIME/.} - start2 )) printf '%7.4f %s %s\n' ${elap::-6}.${elap: -6} ${rx@A} ${tx@A} echo $(( start2 - start )) $(( rx - orx )) $(( tx - otx )) echo >&$zmin 'exit' while read -u $zmout -t .3 line; do : # echo $line done