LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   telnet script (https://www.linuxquestions.org/questions/linux-newbie-8/telnet-script-594806/)

peji 10-26-2007 10:29 AM

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 :cool:, but I donīt understand how :cry:, 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.

MensaWater 10-26-2007 03:33 PM

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.

peji 10-27-2007 06:52 AM

Hi,

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

Thanks.


All times are GMT -5. The time now is 04:20 AM.