expect

Ask for new features here.

Moderator: Pablo

Post Reply
jbassett
Member
Posts: 21
Joined: Tue Sep 15, 2009 10:44 am
Location: Thurrock, Essex, England
Contact:

expect

Post by jbassett » Fri Oct 23, 2009 12:22 am

Hello

Would it be possible to build the 'expect' utility into the next build, this can be very useful when writing scripts to check for backends, and for setting up power off scripts etc.

Thankyou

Jason
Corrilan IT Consultancy Ltd
http://www.corrilan.com
01375 403508
enquiries@corrilan.com

Pablo
Site Admin
Posts: 4182
Joined: Tue Dec 14, 2004 2:13 am
Location: La Jolla
Contact:

Re: expect

Post by Pablo » Fri Oct 23, 2009 2:36 am

It has been a decade since I made extensive use of expect. My understanding is that expect depends on TCL. If this is the case, then including expect would mean including TCL (or a subset of TCL).

In MinIMyth, I do some expect like behavior using perl. While it would have been somewhat simpler using expect, I used perl because I was including perl in MiniMyth for other reasons (multiple Myth plugins use it). Before that, I was using rather convoluted shell and sed processing to accomplish it.

Do you have a script that uses expect that you would like to use? If so, could you post it so that I can see whether or not it is reasonable (though not optimal) to do it using perl?
MiniMyth running on an Acer ApireRevo 3610 and a Zotac ZBOX-ID80-U. Find out more at my MythTV page.

jbassett
Member
Posts: 21
Joined: Tue Sep 15, 2009 10:44 am
Location: Thurrock, Essex, England
Contact:

Re: expect

Post by jbassett » Fri Oct 23, 2009 3:47 pm

I generally use this expect script from clients so that they can find out if a backend machine is active:

#!/usr/bin/expect
global expect_out
spawn telnet 172.16.1.180 6546
expect "#"
send "quit\n"
set igot $expect_out(buffer)
return $igot

Since I posted my request I have altered my system to use this which just pings the backend:

#!/bin/sh

# This script turns the monitor of the front end either on or off.
# Also wakes the backend if required.

checkbackend()
{
pingable=`ping -c1 172.16.1.180 | grep Unreachable`
if [ $? -eq 1 ]
then
echo "The back end appears to be active already."
else
echo "No active back end detected, assuming it is off."
wakelan 00:01:80:63:51:62
fi
}

status=`cat /home/minimyth/scripts/status.txt`

if [ $status = "on" ]
then
sleep 1 && xset dpms force off
echo off > /home/minimyth/scripts/status.txt
else
checkbackend
echo on > /home/minimyth/scripts/status.txt
sleep 1 && xset dpms force on
fi

Jason
Corrilan IT Consultancy Ltd
http://www.corrilan.com
01375 403508
enquiries@corrilan.com

Pablo
Site Admin
Posts: 4182
Joined: Tue Dec 14, 2004 2:13 am
Location: La Jolla
Contact:

Re: expect

Post by Pablo » Sat Oct 24, 2009 4:15 pm

Scripting MythTV's network control interface is the same reason I had wanted expect. When I did it using sh and netpipes it was rather convoluted. However, using perl, it is not too bad. Here is the perl code that I use for network control.

Code: Select all

sub networkcontrol
{
    my $command = shift;

    my @lines = ();

    my $telnet = new Net::Telnet('Timeout' => '10',
                                 'Errmode' => 'return',
                                 'Host'    => 'localhost',
                                 'Port'    => '6546',
                                 'Prompt'  =>  '/\# $/');
    if (($telnet) && ($telnet->open()))
    {
        $telnet->waitfor($prompt);
        @lines = $telnet->cmd($command);
        $telnet->cmd('exit');
        $telnet->close;
        chomp @lines;
    }

    return \@lines;
}
MiniMyth running on an Acer ApireRevo 3610 and a Zotac ZBOX-ID80-U. Find out more at my MythTV page.

Post Reply