Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 May 2005 09:33:18 -0500
From:      Phusion <phusion2k@gmail.com>
To:        Mike Jeays <Mike.Jeays@rogers.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Help with Expect
Message-ID:  <c3ed3fdc05052307335add3e32@mail.gmail.com>
In-Reply-To: <1116818369.953.54.camel@chaucer>
References:  <c3ed3fdc0505221730c273026@mail.gmail.com> <1116818369.953.54.camel@chaucer>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <Mike.Jeays@rogers.com> 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
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?c3ed3fdc05052307335add3e32>