Interesting question actually !!
The command to find and kill the telnet process would be
kill `ps | grep [t]elnetd | cut -f3 -d' '`What this does, is it evaluates the commands between the `` which find the process id, and then return that to kill, which kills it. ps shows the running processes. This is piped with | to grep. That means the output of ps is the input for the grep command which searches for a line containing telnetd and returns that line. The [t] bit stops it returning its own process as otherwise we would get two lines. The output of grep is sent (piped) to the cut command which uses a space as a delimiter (-d' ') and returns the third field (-f3) which is the pid (process id).
To restart we just need to type telnetd
Luckily, the ECI has a sleep command, so the full line would be
kill `ps | grep [t]elnetd | cut -f3 -d' '` && sleep 2 && telnetd & which will kill telnet, and restart it two seconds later.
We can write a script that uses this line, then sleeps for a period of time and then repeats, thus restarting telnet after a specified period.
#!/bin/sh
while true
do
kill `ps | grep [t]elnetd | cut -f3 -d' '`
sleep 2
telnetd
sleep 14400
done
There is a problem though
The router's filesystem is read-only, so it's impossible to create a script. It
is possible though to write the entire thing on one line
while true;do kill `ps | grep [t]elnetd | cut -f3 -d' '`; sleep 2; telnetd; sleep 14400; done
I have tested this, and it works. You can adjust the timing by altering the second sleep command as required. The duration is in seconds so 14400 = 4 hours. You will be logged out immediately on executing the line obviously. A reboot will necessitate re-entering the line.