LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-08-2021, 10:24 PM   #1
vershooter
LQ Newbie
 
Registered: Jul 2020
Posts: 5

Rep: Reputation: Disabled
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
 
Old 11-09-2021, 12:21 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
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.
 
Old 11-09-2021, 01:35 AM   #3
GentleThotSeaMonkey
Member
 
Registered: Dec 2016
Posts: 338
Blog Entries: 4

Rep: Reputation: 128Reputation: 128
This web-search finds some LQ stuff: bash script telnet site:linuxquestions.org
 
Old 11-09-2021, 03:40 AM   #4
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Must it be Bash? If not, see https://metacpan.org/dist/Net-Telnet
 
1 members found this post helpful.
Old 11-09-2021, 07:56 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by vershooter View Post
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.
As others have pointed out, there are MANY easily found examples of telnet scripts on this site, and thousands more you can find with a brief Internet search.

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>'
...and have it be secure and easier to use.

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.
 
Old 11-09-2021, 02:30 PM   #6
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,978

Rep: Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624
I might look at expect and autoexpect.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
telnet slowness - linux telnet vs windows telnet vahab Linux - Networking 4 01-23-2013 02:25 PM
ssh then telnet vs telnet then telnet sanabani Linux - Networking 1 12-20-2011 07:39 PM
enable telnet but can't telnet from the computer guanyu Linux - Networking 8 08-26-2002 06:34 AM
to telnet or not to telnet shogun Linux - Networking 2 04-06-2002 05:38 AM
telnet local but no-telnet via internet blacksheep Linux - Networking 7 11-26-2001 02:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration