Telnet and ssh in a script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Telnet and ssh in a script
# 1  
Old 06-09-2007
Telnet and ssh in a script

dear all,
I know that this question has been asked before frequently, but I really don't get it. My question is composed of several ones.

First:To telnet through a script, I was told to use the way described below, and it works for me, but i don't understand the syntax here. according to the piping, echoing the username, the password and the commands are done first, then the telnetting.. How is that?!
( echo open hostname
sleep 5
echo username
sleep 1
echo password
sleep 1
echo some more output, etc. ) | telnet

Second: Is that the only way that I can do telnet through a script in UNIX?
Third: What about SSH, I know that I can't do the samething with ssh, Is there another way??
Thanks for your concern...
Marawan
# 2  
Old 06-09-2007
Quote:
Originally Posted by marwan
Second: Is that the only way that I can do telnet through a script in UNIX?
definitely not the only way. do you know any other programming languages? eg Perl/Python ? if you know them, there are telnet modules you can use to program telnet sessions.

Quote:
Third: What about SSH, I know that I can't do the samething with ssh, Is there another way??
ssh can execute remote commands. check your man page. it should be something like this: ssh <options> command
# 3  
Old 06-09-2007
Quote:
Originally Posted by marwan
What about SSH, I know that I can't do the samething with ssh, Is there another way??
SSH is much more powerful, you use the command line and arguments to do the authentication and then stdin/stdout/stderr are effectively pure pipes to the shell or program at the remote end.

If you have your public key installed in your $HOME/.ssh/authorized_keys on the remote machine then all you need to do is things like

to get a remote directory listing...

Code:
ssh remote-host-name ls -l

or

Code:
ssh fred@foobar ls -l

or to unpack a tar file on a remote machine....

Code:
cat some.tar | ssh remote-host tar xvf -

# 4  
Old 06-11-2007
Take a look at this thread also, hope it helps a bit.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

No terminal (tty) after ssh and telnet also

Hi all, we are just confused about a strange problem on one server in production (XServer, running OSXS 10.5.6). It works normal for month. Since two day everthing seems to be fine also with one exception. When we connect trough ssh we won't get a tty session. For testing purposes, we enabled... (2 Replies)
Discussion started by: Frank.Knobloch
2 Replies

2. SuSE

Unable to telnet (non-ssh) as root

Hi forum, I face a strange issue. I'm able to telnet as root with ssh. But I'm not able to telnet (non-ssh) as root to my Suse 10 machine. Can someone please point to significant files where I need to make changes for Suse 10 machine and resolve this issue. Thanks in advance. (2 Replies)
Discussion started by: anilgurwara
2 Replies

3. Shell Programming and Scripting

Need 'expect' help, ssh/telnet and trapping

So here is what I am trying to do. I have a large # of switches and routers I am trying to log into. Unfortunately some have ssh only, some have telnet only. and some i have never logged into with ssh. I first want it to SSH, if i have never logged into the box it will ask for adding the ssh key. I... (0 Replies)
Discussion started by: ippy98
0 Replies

4. AIX

Problems with SSH / telnet

Hey, I have upgraded 3 servers from SSH Tectia 4.0.3 to SSH Tectia 6.0.2. 2 of them are working fine but one server suddenly began to have troubles after about 2 hours. Now it is impossible to login to this server using SSH and even telnet. When SSH is running on this particular server, the CPU... (20 Replies)
Discussion started by: Hille
20 Replies

5. Shell Programming and Scripting

TELNET to SSH

Hi All, I was implementing a change of TELNET to SSH connectivity, and finding it tough at a point where I was connecting to another unix server through TELNET. ( ps -ef |grep abcd) | TELNET x.xx.xxx.xx now I when I tried to replace TELNET with SSH, i am not able to connect. ( ps -ef... (1 Reply)
Discussion started by: pranavagarwal
1 Replies

6. UNIX for Dummies Questions & Answers

like ssh telnet

I want to learn some commands like ssh, telnet and others where i can be tease. thanks for help... (2 Replies)
Discussion started by: Kostantinos
2 Replies

7. UNIX for Advanced & Expert Users

about ssh and telnet

I amn't advance but i want to learn some commands where here you can help me. i don't learn easy commands but i learn if its good experience and interesting. I want to learn about ssh, telnet and how i can be miff ( i don't speek good english but i hope to understant me) thanks for any help... (1 Reply)
Discussion started by: Kostantinos
1 Replies

8. Solaris

Can ftp but not telnet/ssh/rsh

Hi , I have a Solaris 9 machine in which I can ftp but telnet/rsh/ssh is not working, although it was working before. I cannot also log in through the console. I get the banner for telnet but it kicks me out. Any ideas? rte (2 Replies)
Discussion started by: run_time_error
2 Replies

9. UNIX for Dummies Questions & Answers

telnet ans ssh

Hi all, I need few information as follows: 1. I am acessing one the machine uismg putty at port no 12023 using telnet service. My question is i heard by defalult the port for telnet is 23. Why it is 12023 in my case. Also where can i change it. 2. i install new debian server. And then... (1 Reply)
Discussion started by: gauri
1 Replies

10. Shell Programming and Scripting

script to connect to different ip address thro telnet or ssh

Hi, I have three ip address say x.x.x.x , y.y.y.y and z.z.z.z I am connecting to x.x.x.x first and from there i do telnet or ssh to y.y.y.y and getting into y and from there i do telnet or ssh to z.z.z.z i want to know, can we write a script, which can automatically connect from x to y... (3 Replies)
Discussion started by: vasikaran
3 Replies
Login or Register to Ask a Question