I have a modem which I need to reboot from a router. A modem accepts only telnet and has a Web GUI. If I telnet from the router manually, I can reboot the modem with no problem at all.

But when I try to issue following at the router:

(sleep 1; echo usr; sleep 1; echo pwd; sleep 5; echo reboot; ) | telnet

it will log me in, show a prompt # at the router, but it will never do the third command. What am I doing wrong?

For test purposes:

  1. I tried using ls instad of reboot
  2. I tried varying the sleep lengths
  3. I tried from a Raspberry Pi instead of from a router

but I can never get a modem to accept and/or execute any command after a login using telnet this way.

I have no expect available. I would prefer to solve it using router's sh script as it already does several things there.

  • 1
    I don't know why it doesn't work, but to get rid of the sleep stuff (which is unreliable guesswork at best), you can e.g. use expect and send off the next command at the next prompt.
    – dirkt
    Oct 12, 2016 at 15:48

2 Answers 2


I was too quick. It works with:

(sleep 1; echo usr; sleep 1; echo pwd; sleep 1; echo ls; sleep 1; ) | telnet
  • Is this an answer or an update to your question? If it's your own answer please accept it (with the tick mark) so we know it's resolved. If it's an update to your question please edit your question instead, and delete this non-answer. Oct 12, 2016 at 21:43

You need a trailing sleep to allow the router time to action the reboot command before the telnet session is closed. I'd suggest two seconds but you may need to tweak this for your situation.

Try this

( s(){sleep "${1:-1}";}; s; echo usr; s; echo pwd; s; echo reboot; s 2 ) | telnet

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .