non-interactine telnet session
WATANABE Katsuhiro
katsu at sra.co.jp
Sat Aug 18 18:57:59 AEST 1990
In article <1995 at xn.LL.MIT.EDU> healey at 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.
More information about the Comp.unix.questions
mailing list