Visit Our UNIX and Linux User Community

Odd quirk with xargs and telnet

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Odd quirk with xargs and telnet
# 1  
Old 09-29-2010
Odd quirk with xargs and telnet

For a variety of strange reasons, I've set up an arrangement by which a server responds with "Hi there" if I connect on a specified port. This is a typical transaction:
# telnet 3334
Trying 123.456.789.101...
Connected to
Escape character is '^]'.
Hi there
Connection closed by foreign host.

Now, I'm trying to use a quick and dirty way to do this concurrently, using xarg's -P (or max-procs, in some cases) option. Once this works, I'll increase the seq value, add -P concurrency, and be happy. The problem, though, is that I can't get the server's response to show up. Here's a trivial case:

# seq 1 | xargs -I DISCARD telnet 3334
Trying 123.456.789.101...
Connected to
Escape character is '^]'.
Connection closed by foreign host.

So, the "1" should be discarded, as there is no DISCARD string in the command called by xargs, and the telnet command should be run. But, this trivial case should be the same thing as just running the telnet command alone since it's wrapped up in a negligible xargs. But, for some reason, the server's "Hi there" doesn't appear. Any idea why that is? I've tried redirecting stderr to stdout on the chance that it's some oddity in the way xargs handles errors, but no luck. I've also placed the telnet command into a little one-liner script and called that instead, without changing the output. Any suggestions? I've scratched my head many times. It didn't help... Many thanks in advance.

Last edited by treesloth; 09-29-2010 at 10:18 PM..
# 2  
Old 09-30-2010
It seems to have something to do with networking. Try
seq 1 | xargs -I DISCARD telnet 3334 |cat

This User Gave Thanks to binlib For This Post:
# 3  
Old 09-30-2010
Tragically, that seems not to have helped, although it made me wonder (chasing low-percentage possibilities now...) if perhaps special character information exists. Alas, piping through cat -e showed nothing of value. This is truly strange.

On a related matter, is this the proper board for a thread like this? I'm not quite clear on what's basic and what allows me to sit at the grown-ups table. :-)
# 4  
Old 09-30-2010
It's because, when run with xargs, the commands have no standard input connected. Usually it'd wait for input, either from your end or the other end, but now it connects, tries to read from the keyboard, gets EOF, and quits instantly instead.

You can get around this by giving xargs a file listing arguments instead of reading them from stdin, i.e. list-servers > filename ; xargs -a filename command but it still requires stdin to be something terminal-like, meaning, it'd break down again if you tried to run this from a cron job instead of a terminal. 'telnet' may not be the best command for this, you might want to investigate netcat(nc)
These 2 Users Gave Thanks to Corona688 For This Post:
# 5  
Old 09-30-2010
Sure enough, that works. Thanks for the help. And you're right... telnet is a rather awkward tool for this. I decided not to use netcat because I wasn't aware it existed :-). Many thanks for the pointer. It looks like a very broadly-applicable tool that's very much worth learning about.

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Odd vi error

Hello, I have a weird think going on, on one of my servers. vi filename "/var/tmp" No such file or directory What going on here? (4 Replies)
Discussion started by: bitlord
4 Replies

2. UNIX for Dummies Questions & Answers

Difference Between Krb5-telnet And Ekrb5-telnet

Hi, I want to know the difference between these two services. Both are under xinetd. Both are used for enabling and disabling Telnet service. So, can somebody please explain me the difference between the two ? Thanks in advance :) (0 Replies)
Discussion started by: kashifsd17
0 Replies

3. UNIX for Dummies Questions & Answers

Automatically login in the telnet from present telnet

Hi, I was writing one script which includes to switch to the another telnet automatically from the present telnet server. I was using rlogin but firstly it takes the same user name of the present telnet and secondly it is prompting for the password. But i want to switch to the another telnet... (2 Replies)
Discussion started by: Prateek
2 Replies

4. Programming

printf quirk

Hi, Could anyone explain me the logic behind the following program's output? int main() { printf("%d\n", printf("%d %d", 2, 2) & printf("%d %d", 2, 2)); printf("%d\n", printf("%d %d\n", 2, 2) & printf("%d %d\n", 2, 2)); } Ans: 2 22 23 2 2 2 2 4 (2 Replies)
Discussion started by: royalibrahim
2 Replies

5. UNIX for Dummies Questions & Answers

Finding the odd one out!

Hi guys, I wondered if someone would be able to help me. I have a number of files which all have entries in them looking something like; And I'm looking for a way where by I can compare a number of these files and identify the odd numbers in the sequence. So for example if I had to... (1 Reply)
Discussion started by: JayC89
1 Replies

6. Shell Programming and Scripting

Webpage to Telnet via Perl and Expect: Telnet problem?

Somewhat long story: I have a simple Perl CGI script that uses Expect to Telnet to a device and grab some data, and then spits it back to Perl for display on the Webpage. This works for many devices I've tried, but one device just fails, it keeps rejecting the password on this device, only... (1 Reply)
Discussion started by: jondo
1 Replies

7. Solaris

Daylight Savings Time Quirk

I am running a SUN E450 on solaris (5.7). I have applied the DST patch and the system time is correct. However when users login the get the time wrong (+4 hours) (I am in EDT Zone). Does anyone know where a system wide variable for this could be set. (Root user gets the right time) Frank (3 Replies)
Discussion started by: frankkahle
3 Replies

8. UNIX for Dummies Questions & Answers

even odd script

I need a unix script that check for even or odd. EXAMPLE:::: please enter the number to check: 12 the output: This is an even number it has to have prompts. (2 Replies)
Discussion started by: snyper2k2
2 Replies

9. Linux

odd telnet problem

Hey, I've got a RH9 box running telnet-server 0.17-25. Now i don't know what the problem is and i've been reading all night trying to find somthing like it. I am able to open a telnet session on the box using localhost and address) but if i try to do it from another... (7 Replies)
Discussion started by: byblyk
7 Replies

Featured Tech Videos