[comp.unix.questions] non-interactine telnet session

healey@XN.LL.MIT.EDU (Joseph T. Healey) (08/14/90)

Is there any way to invoke a non-interactive telnet session
via a script (preferably csh or sh) ?

We would like the script to:

	log into the target machine
	run an arbitrary number of commands listed in the script
	log out of the target machine

Thanks in advance.

katsu@sra.co.jp (WATANABE Katsuhiro) (08/18/90)

In article <1995@xn.LL.MIT.EDU> healey@XN.LL.MIT.EDU (Joseph T. Healey) writes:

> Is there any way to invoke a non-interactive telnet session
> via a script (preferably csh or sh) ?
> 
> We would like the script to:
> 
>         log into the target machine
>         run an arbitrary number of commands listed in the script
>         log out of the target machine

 If we are able to pipe from/into "telnet", you know the rest.
 When you send command-lines to telnet(to shell of remote site) through
pipe, time intervals need to be put between the lines. Naturally, we
should wait for prompts. But it is too hard to do in sh/csh. So...
how about sleeping?


#!/bin/sh
remotehost="srava"
loginname="katsu"
password="neverpeek"

(sleep 10
echo "$loginname"; sleep 2
echo "$password"; sleep 10

echo "date"; sleep 2
echo "ls -l"; sleep 3
echo "bc"; sleep 1
        echo "for (i = 0; i < 100; i++) j =  i * i"; sleep 1
        echo "j"; sleep 1
        echo "quit"; sleep 1
echo "exit") | telnet "$remotehost"



 You may add other pipes to last line.

Caution:
1. I strongly discourage from using script like this, because it contains
the password as plain text. You ought to rewrite it to ask password each
start up time, if possible.
2. There is no assurance that it works every time. For example, the first
sleeping interval(`sleep 10' in my example) was too short to come up 
login prompt, it would fail to login. Anyway, it is tiresome to tune
intervals after each command invoking.

----____----____
WATANABE Katsuhiro      Software Research Associates, Inc. Japan.
Not execute, but evaluate.

jon@savant.uucp (Jon Gefaell) (08/18/90)

In article <1995@xn.LL.MIT.EDU> healey@XN.LL.MIT.EDU (Joseph T. Healey) writes:
>
>Is there any way to invoke a non-interactive telnet session
>via a script (preferably csh or sh) ?
>
>We would like the script to:
>
>	log into the target machine
>	run an arbitrary number of commands listed in the script
>	log out of the target machine
>
>Thanks in advance.

Uhm, you've heard of UUCP, right? Give that a try, seems like the perfect
tool for what you like. Remember, UUCP isn't just for modems... :)


BTW, I'm a UNIX.NOVITIATE, I'd _love_ to hear what people think...
-- 
+----------- Domain? DOMAIN? We Don't Need No Steeeenkin' Domain! -----------+
|I wish I had something interesting to put in my .signature file, but I don't|
+-savant!jon@virginia.edu {...}!uunet!virginia!savant!jon jeg7e@virginia.edu-+