Date: Sun, 22 May 2005 23:19:29 -0400 From: Mike Jeays <Mike.Jeays@rogers.com> To: Phusion <phusion2k@gmail.com> Cc: freebsd-questions@freebsd.org Subject: Re: Help with Expect Message-ID: <1116818369.953.54.camel@chaucer> In-Reply-To: <c3ed3fdc0505221730c273026@mail.gmail.com> References: <c3ed3fdc0505221730c273026@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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? ----------------------------------------------------- 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."
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1116818369.953.54.camel>