Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 May 2005 11:37:24 -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:  <1116862644.5643.0.camel@chaucer>
In-Reply-To: <c3ed3fdc05052307335add3e32@mail.gmail.com>
References:  <c3ed3fdc0505221730c273026@mail.gmail.com> <1116818369.953.54.camel@chaucer> <c3ed3fdc05052307335add3e32@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 2005-05-23 at 10:33, Phusion wrote:
> 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?
> > 
> > -----------------------------------------------------
> > 
> > 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."
> > 
> > 
> >
> _______________________________________________
> 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"
> 

Maybe this will help a little more:

#!/usr/local/bin/expect
spawn ping -c 1 faraday

expect {
  "faraday ping statistics" {puts OK\n;   set FLAG 0; exp_continue}
  "Unknown host"            {puts DOWN\n; set FLAG 1; exp_continue}
}

puts "FLAG=$FLAG\n"






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