From owner-freebsd-questions@FreeBSD.ORG Mon May 23 14:33:22 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 983C816A41C for ; Mon, 23 May 2005 14:33:22 +0000 (GMT) (envelope-from phusion2k@gmail.com) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2516B43D1D for ; Mon, 23 May 2005 14:33:22 +0000 (GMT) (envelope-from phusion2k@gmail.com) Received: by rproxy.gmail.com with SMTP id b11so937084rne for ; Mon, 23 May 2005 07:33:18 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=VEzHldNz0FBFpR3Zv5tAMccTtY/Q2vHLLbkbFJlRG1YQ1MErM7SSFzlHeTDiFVa+xZRtVGWM5BzJRXlBQJlXf5CkpBLoXnvOSUyg+pdPFQBZXjjrIYVBbXo3rmBrk8J5osZnL8lIwF+u5DiI+5n8yUJPqBGq+XUrEPNZsSzyXYs= Received: by 10.11.122.47 with SMTP id u47mr39438cwc; Mon, 23 May 2005 07:33:18 -0700 (PDT) Received: by 10.11.100.43 with HTTP; Mon, 23 May 2005 07:33:18 -0700 (PDT) Message-ID: Date: Mon, 23 May 2005 09:33:18 -0500 From: Phusion To: Mike Jeays In-Reply-To: <1116818369.953.54.camel@chaucer> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <1116818369.953.54.camel@chaucer> Cc: freebsd-questions@freebsd.org Subject: Re: Help with Expect X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Phusion List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 May 2005 14:33:22 -0000 Mike, I need to this be in an expect script because I will be entering commands after I telnet into the machine. Thanks for the help though. On 5/22/05, Mike Jeays wrote: > On Sun, 2005-05-22 at 20:30, Phusion wrote: > > I need some help with an expect script I'm trying to write. Here's > > what I would like to do. > > > > - Ping the host to see if it's up. > > a. If the host responds to pings telnet into it. > > b. If the host doesn't respond to pings write that to a log file and > > close the expect script properly. > > > > The host does respond to pings. I was thinking if I see a ttl in the > > response packet to assume it's up and telnet into it. Let me know how > > I can do the following with expect. Also, how do I close an expect > > script properly? Thanks. > > _______________________________________________ > > freebsd-questions@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd= .org" > > > I sent you these examples to a similar request a few days ago, and > didn't get any acknowledgement. Did you not receive it, or is it not > clear, or do you need more help? >=20 > ----------------------------------------------------- >=20 > You can ping a host and test whether it was successful from a shell > script, without needing to use expect. Hope this is useful, as it > doesn't quite answer your question. Note the "-c 1" to tell ping to try > just once. >=20 > ping -c 1 chaucer > rc1=3D$? > if [ $rc1 -gt 0 ] > then > echo "Chaucer is down" > else > echo "Chaucer is up" > fi >=20 > Here is an example of telnet from expect; a very quick and dirty way to > synchronize a clock on a very old machine. >=20 > #!/usr/local/bin/expect > set timeout 10 > spawn telnet jansen > expect "]" >=20 > send "password1\r" > expect "jansen???" >=20 > send "su\r" > expect "Password:" >=20 > send "rootpassword\r" > expect "#" >=20 > exec date >/tmp/datesync.tmp > exec cat /tmp/datesync.tmp > set newtime [exec cat /tmp/datesync.tmp] > send "date -s \"$newtime\"\r" > expect "#" >=20 > send "exit\r" > expect "jansen???" >=20 > send "exit\r" > expect "host." >=20 >=20 >