LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-26-2007, 11:29 AM   #1
peji
LQ Newbie
 
Registered: Mar 2005
Posts: 12

Rep: Reputation: 0
telnet script


Hi folks,

just by searching here I've found this script, which automates a telnet connection to a host:

#!/bin/sh

host=10.0.0.1
port=23
pass=xxxx
cmd1=24
cmd2=4
cmd3=21

( echo open ${host} ${port}
sleep 1
echo -e "\r"
sleep 1
echo ${pass}
sleep 1
echo -e "\r"
sleep 1
echo ${cmd1}
sleep 1
echo -e "\r"
sleep 1
echo ${cmd2}
sleep 1
echo -e "\r"
sleep 1
echo ${cmd3}
sleep 1
echo -e "\r"
sleep 1
echo exit ) | telnet host

I have also checked and it runs , but I donīt understand how , I mean what I see are some commands which output goes to the telnet application through a pipe, but when I run the script it seems as the telnet was executing first instead of the group of the commands before te pipe (echo and sleep commands).

Any feedback about this will be welcome.

Thanks in advance.

Jose.
 
Old 10-26-2007, 04:33 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,577
Blog Entries: 14

Rep: Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969
You misunderstand how a pipeline works. While it does in fact execute what is done on the left side of the pipe first it won't show it to you because the pipe redirects all output of the left side into the right side. From your viewpoint what is being executed is the right side as if the left side was being used as part of its input line.

Similarly if you're in a directory and do "ls |sort" you won't see the original ls output - you'll just see the sorted output. If it didn't work that way you'd see the unsorted output and then the sorted output which would not be very useful.
 
Old 10-27-2007, 07:52 AM   #3
peji
LQ Newbie
 
Registered: Mar 2005
Posts: 12

Original Poster
Rep: Reputation: 0
Hi,

firstly thanks for your reply. You're right I was confused about how pipeline works so now it's a little bit more clear.

Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Running Telnet in a script, want to save Telnet output, howtodothis??? anil3 Linux - Software 2 03-08-2006 05:01 PM
Telnet script pirra Programming 1 12-29-2004 04:04 PM
Telnet script?? mike400hp Linux - Newbie 6 08-22-2003 04:41 PM
telnet script tn1681 Linux - General 3 07-25-2002 11:09 PM
telnet script tn1681 Programming 2 07-24-2002 09:47 PM


All times are GMT -5. The time now is 04:45 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration