Scripting for telnet
HI,
Newbie here. I just want to ask how to do bash script like to telnet IP PORT() then after connected I will type status. then I will see how many connection I created. I want to create a script that for example connections is above 5 then it will restart a service. Do you have insight for this one. Thanks |
That could probably be scripted using expect, which is written in Tcl. Most of the links from the project home page are dead, but you might find them via the Internet Archive, if it's that important: https://core.tcl-lang.org/expect/
But what problem are you trying to solve? There are probably better tools for the task than the telnet client. |
This web-search finds some LQ stuff: bash script telnet site:linuxquestions.org
|
Must it be Bash? If not, see https://metacpan.org/dist/Net-Telnet
|
Quote:
To add to that, I would strongly suggest you rethink your approach. First, telnet isn't even installed on most distros of Linux these days because it is horribly insecure, so your first step in your 'script' would be to install and configure an insecure service on your server. Then open your firewall ports to accommodate that service...neither is good. Second, you can use SSH easily, and (after you do a keyswap) can have your command on the same line, such as: Code:
ssh user@server.com '<your command goes here>' Aside from those suggestions, bear in mind that you can also easily have a script ON the server itself to monitor that service, and act accordingly, without the need to run any commands over the network. |
I might look at expect and autoexpect.
|
All times are GMT -5. The time now is 10:37 PM. |