Path: sran124!katsu From: katsu@sra.co.jp (WATANABE Katsuhiro) Message-ID: Date: 18 Aug 90 17:57:59 Organization: Software Research Associates, Inc.,Japan Newsgroups: comp.unix.questions Subject: Re: non-interactine telnet session Distribution: world In-reply-to: healey@XN.LL.MIT.EDU's message of 14 Aug 90 13:04:51 GMT References: <1995@xn.LL.MIT.EDU> 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.