# Telnet shortcut?



## evildan (Aug 22, 2002)

Okay, newbie question, but is there a way to create a shortcut so instrad of typing this in the terminal:


```
telnet host.com

login: username
password: password

cd directory1/directory2/directory3
```

So I'm looking for a 1 command shortcut solution to login and get me to a specified directory.

Any help would be appreciated.


----------



## fddi1 (Aug 23, 2002)

Yes, you can write an expect script and run that script every time you want to do the action.


----------



## hazmat (Aug 23, 2002)

To log in with one command, you can use rlogin/slogin.  And to get you to a particular directory, as fddi1 said, I guess you can use it in an expect script.


----------



## evildan (Aug 23, 2002)

Let's pretend I'm UNIX dumb... how would I go about writing and implementing a script?


----------



## Gwailo (Aug 25, 2002)

I would have said modify the file ~/.cshrc but I do not believe that this is an explicit script. So when you created an alias if would type your username after telnet had been terminated, etc...

Try a PERL, I don't know PERL tho...


----------



## TBoNe (Aug 26, 2002)

PERL itself will not telnet to a server, you would need to install a module called Net:Telnet that PERL will call for. It works quite well as I have written several scripts for work thet telnet to switches/routers and perform some maintenance.

Perhaps a shell script would be a soluition?


----------



## symphonix (Aug 27, 2002)

Create a shell script with the extension ".TERM", this will open in terminal by default when you double-click it. It might read something like this:

#!/usr/bin/sh
# Shell script to connect to Telnet host

telnet username@my.telnet.net


You'd still need to put in your password (I think expect could be used to get around this, not sure how)

Now what ???


----------



## DMCrimson (Aug 27, 2002)

I have nothing else to add to this, but if possible, use ssh, telnet is not encrypted, so it's highly unsecure if someone indeed is "listening"

oh, one more addition:
_
#!/usr/bin/sh 
# Shell script to connect via ssh to host 

ssh -l [username] [host]
_

that -l option logs you in with [username] to [host], I've not yet found a way to add the password...
save the file to your home-folder, and chmod 755 it.
you can later on run it in terminal with ./filename


----------



## hazmat (Aug 27, 2002)

> _Originally posted by symphonix _
> *You'd still need to put in your password (I think expect could be used to get around this, not sure how)
> *



I'm not familiar with Expect, but maybe you could use an include type statement to pull in the password from another file, with 600 permissions.  Or maybe just make the Expect script 600.


----------



## fddi1 (Aug 27, 2002)

> _Originally posted by evildan _
> *Let's pretend I'm UNIX dumb... how would I go about writing and implementing a script?
> 
> *



First of all, you need to install Expect.  Expect is just like perl, but I don't believe it's installed by default in OS X.  Anyway, you'll need tcl libraries for Expect too.  

So once you have the software installed. O'Reiley has a very good book on how to write expect scripts.  The thing you want to do is fairly easy.  Once you are familir with the concept, it will probably take about 5 minutes to write the actual script.


----------

