OpenWrt Forum Archive

Topic: [Solved]Issue Telnet commands from Crontab in OpenWrt

The content of this topic has been archived on 13 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

My router setup is like this:

DSL Modem @ 192.168.10.1 -- Main gateway
Openwrt Router @ 192.168.10.254 -- internet access
Wirelessly connected to each other through Relay configuration.

Everything is working fine as my system is rather simple one and just need internet access. Sometimes the main router loses connectivity and i have to either reboot it manually or issue a telnet command to do it. I want to know if it is possible to issue Telnet commands as a scheduled task in Openwrt from the Crontab. Or is there anything else that can be done to either reboot the main router. Main router doesn't have Openwrt because it comes from the ISP and it works on ADSL and i cant really use USB stick with my second router but i am willing to uninstall Luci and create my own firmware for the router. I already have installed a custom firmware created from image builder. So please tell me any pointers if this is possible. Thanks

(Last edited by redd_llining on 7 Nov 2017, 09:34)

Yes, you can there are many ways but a very simple stupid hack can work too

inside a script...

telnet 192.168.10.1 <<EOF
userid
passwd
reboot #or whatever it takes to reboot it
EOF


Most ISP modems have a bridge mode so you can handle all the clients and routing on your own router and that may eliminate the issue the main router is having as well.

There are other commands that linux has such as expect which would make this more robust

If your main router can support ssh/rsh that would be the easiest way to go aside from bridging

FYI telnet is no longer included by default in openwrt so you'd have to add it to your config.

Can you tell me what telnet package do i need? I am not really sure how to find it since i have to recreate the firmware image with the required packages. Thanks

CONFIG_BUSYBOX_CONFIG_TELNET:                                                                                             │
  │                                                                                                                           │
  │ Telnet is an interface to the TELNET protocol, but is also commonly                                                       │
  │ used to test other simple protocols.                                                                                      │
  │                                                                                                                           │
  │ Symbol: BUSYBOX_CONFIG_TELNET [=n]                                                                                        │
  │ Type  : boolean                                                                                                           │
  │ Prompt: telnet                                                                                                            │
  │   Location:                                                                                                               │
  │     -> Base system                                                                                                        │
  │       -> busybox................................ Core utilities for embedded Linux (PACKAGE_busybox [=y])                 │
  │         -> Networking Utilities                                                                                           │
  │   Defined at package/utils/busybox/config/networking/Config.in:797                                                        │
  │   Depends on: PACKAGE_busybox [=y] && BUSYBOX_CUSTOM [=y]

I managed to do it and without the use of script file since it was always saying permission denied. I issue a single command with sleep parameter to issue commands at different stages.

( sleep 1; echo admin; sleep 1;  echo password; sleep 1; echo adsl connection --down; sleep 20; echo adsl connection --up; sleep 6; ) | telnet 192.168.10.1

Thanks for your help.

(Last edited by redd_llining on 7 Nov 2017, 09:34)

The discussion might have continued from here.