From owner-freebsd-questions@FreeBSD.ORG Sun May 15 19:31:37 2005 Return-Path: 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 CE79E16A4CE for ; Sun, 15 May 2005 19:31:37 +0000 (GMT) Received: from smtp102.rog.mail.re2.yahoo.com (smtp102.rog.mail.re2.yahoo.com [206.190.36.80]) by mx1.FreeBSD.org (Postfix) with SMTP id 0E24E43D92 for ; Sun, 15 May 2005 19:31:37 +0000 (GMT) (envelope-from Mike.Jeays@rogers.com) Received: from unknown (HELO ?192.168.2.150?) (mjeays2551@24.114.152.139 with plain) by smtp102.rog.mail.re2.yahoo.com with SMTP; 15 May 2005 19:31:33 -0000 From: Mike Jeays To: Phusion In-Reply-To: References: Content-Type: text/plain Message-Id: <1116185492.86936.52.camel@chaucer> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Sun, 15 May 2005 15:31:32 -0400 Content-Transfer-Encoding: 7bit cc: freebsd-questions@freebsd.org Subject: Re: Help with Expect Script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 May 2005 19:31:37 -0000 On Sun, 2005-05-15 at 14:09, Phusion wrote: > I'm new to writing expect scripts and need some help. The script will > telnet to a host and run some commands. I want the script to ping the > host to see if it's alive first before it telnets into it. Also, I > know the host is pingable meaning it responds to pings. If the host > doesn't respond to a ping I want it to log that to a log file and then > quit. I already know how to telnet to the host, but not sure about the > ping part and writing it to a log file. Could you please reply to this > email with a little example script. Thanks. > > Phusion > _______________________________________________ > 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" > 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. ping -c 1 chaucer rc1=$? if [ $rc1 -gt 0 ] then echo "Chaucer is down" else echo "Chaucer is up" fi Here is an example of telnet from expect; a very quick and dirty way to synchronize a clock on a very old machine. #!/usr/local/bin/expect set timeout 10 spawn telnet jansen expect "]" send "password1\r" expect "jansen???" send "su\r" expect "Password:" send "rootpassword\r" expect "#" exec date >/tmp/datesync.tmp exec cat /tmp/datesync.tmp set newtime [exec cat /tmp/datesync.tmp] send "date -s \"$newtime\"\r" expect "#" send "exit\r" expect "jansen???" send "exit\r" expect "host."