I have a shell script which runs an expect script which, in turn, connects to my router and reboots it. I've had something very like it for ages but I've had a problem ever since a recent upgrade to RH7.2.
Basically, the script works fine in the foreground; it works fine under "at now +1 minute"; it works fine under "batch" BUT it always fails when run under cron.
The relevant output from failed jobs looks like:
---------------------------------------------------------------------- spawn telnet my-router Trying 192.168.0.254... Connected to my-router. Escape character is '^]'.
Password: Connection closed by foreign host. send: spawn id exp3 not open while executing "exp_send -s -- $arg" (procedure "send" line 3) invoked from within "send -- "X"" (file "/usr/local/sbin/reboot_router.exp" line 53) ----------------------------------------------------------------------
which seems to show that the telnet session is spawned OK and opens the connection (the "Password: " string comes from the router) but then as soon as expect tries to send the first character of the password, it finds that the telnet session has been closed!
Any ideas, please?
PS. Yes, I know all of the security risks in embedding passwords in scripts and in using telnet rather than ssh!
Regards
Andrew Wallis Fox Cottage Fox Hill St Cross South Elmham HARLESTON IP20 0NX UK
tel: +44 (0)1986 782283 mobile: +44 (0)7860 217025 SMS via email: mailto: +447860217025@mmail.co.uk
Andrew Wallis andrew.wallis@vulpes.demon.co.uk wrote:
Basically, the script works fine in the foreground; it works fine under "at now +1 minute"; it works fine under "batch" BUT it always fails when run under cron.
This makes me think that something wants a tty. I've had similar problems trying to run lynx from cron (don't ask). I don't remember whether you can do something to how it's run from cron to give it one, or whether using something like nc (netcat) instead of telnet may work for you instead.
I got it running on a RH7.1 box at work updating the config on a router on the fly......... I'll see if I can dig up my notes and pass them over to you. Probably won't be till Monday though..
Have you thought about using SNMP, if I remember right it can be done, this way you'll be able to use ACL's....
Simon
On Friday 03 May 2002 6:45 pm, you wrote:
I have a shell script which runs an expect script which, in turn, connects to my router and reboots it. I've had something very like it for ages but I've had a problem ever since a recent upgrade to RH7.2.
Basically, the script works fine in the foreground; it works fine under "at now +1 minute"; it works fine under "batch" BUT it always fails when run under cron.
The relevant output from failed jobs looks like:
spawn telnet my-router Trying 192.168.0.254... Connected to my-router. Escape character is '^]'.
Password: Connection closed by foreign host. send: spawn id exp3 not open while executing "exp_send -s -- $arg" (procedure "send" line 3) invoked from within "send -- "X"" (file "/usr/local/sbin/reboot_router.exp" line 53)
which seems to show that the telnet session is spawned OK and opens the connection (the "Password: " string comes from the router) but then as soon as expect tries to send the first character of the password, it finds that the telnet session has been closed!
Any ideas, please?
PS. Yes, I know all of the security risks in embedding passwords in scripts and in using telnet rather than ssh!
Regards
Andrew Wallis Fox Cottage Fox Hill St Cross South Elmham HARLESTON IP20 0NX UK
tel: +44 (0)1986 782283 mobile: +44 (0)7860 217025 SMS via email: mailto: +447860217025@mmail.co.uk
main@lists.alug.org.uk http://www.anglian.lug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main Unsubscribe? See message headers or the web site above!
Hi Andrew....
Your message made me have a look around, http://pancho.lunarmedia.net/howto.shtml is what I cam up with, I've just tried it on a 1750, 2621, 3662 works a treat... I know what I'll be doing on Monday, getting rid of my expect scripts
Simon
On Friday 03 May 2002 6:45 pm, Andrew Wallis wrote:
I have a shell script which runs an expect script which, in turn, connects to my router and reboots it. I've had something very like it for ages but I've had a problem ever since a recent upgrade to RH7.2.
Basically, the script works fine in the foreground; it works fine under "at now +1 minute"; it works fine under "batch" BUT it always fails when run under cron.
The relevant output from failed jobs looks like:
spawn telnet my-router Trying 192.168.0.254... Connected to my-router. Escape character is '^]'.
Password: Connection closed by foreign host. send: spawn id exp3 not open while executing "exp_send -s -- $arg" (procedure "send" line 3) invoked from within "send -- "X"" (file "/usr/local/sbin/reboot_router.exp" line 53)
which seems to show that the telnet session is spawned OK and opens the connection (the "Password: " string comes from the router) but then as soon as expect tries to send the first character of the password, it finds that the telnet session has been closed!
Any ideas, please?
PS. Yes, I know all of the security risks in embedding passwords in scripts and in using telnet rather than ssh!
Regards
Andrew Wallis Fox Cottage Fox Hill St Cross South Elmham HARLESTON IP20 0NX UK
tel: +44 (0)1986 782283 mobile: +44 (0)7860 217025 SMS via email: mailto: +447860217025@mmail.co.uk
main@lists.alug.org.uk http://www.anglian.lug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main Unsubscribe? See message headers or the web site above!
Many thanks. That pancho info is very useful to me - though not in this instance as the router I'm referring to is my ISDN router at home. It's a cheap & cheerful Zxyel Prestige which does more or less everything I want of it and has done for four years BUT it's unmanaged so SNMP control is out.
As I said, the predecessor of this expect script worked fine under earlier Linux versions. With this one, I had to tweak some delay on transmission values to get it to work at all (I've found that expect sometimes sends data too fast for some devices) and I suspect this may still be the problem (though why different when forked by cron as against at or batch???).
I'll keep tweaking those values today & see if matters improve.
Regards
Andrew Wallis Fox Cottage Fox Hill St Cross South Elmham HARLESTON IP20 0NX UK
phone: +44 (0) 1986 782283 mobile: +44 (0) 7860 217025 SMS via email: mailto:+447860217025@mmail.co.uk
-----Original Message----- From: Simon [mailto:simon@sparksy.org.uk] Sent: 03 May 2002 16:22 To: Andrew Wallis; main@lists.alug.org.uk Subject: Re: [Alug] Any "expect" gurus out there?
Hi Andrew....
Your message made me have a look around, http://pancho.lunarmedia.net/howto.shtml is what I cam up with, I've just tried it on a 1750, 2621, 3662 works a treat... I know what I'll be doing on Monday, getting rid of my expect scripts
Simon
On Friday 03 May 2002 6:45 pm, Andrew Wallis wrote:
I have a shell script which runs an expect script which, in
turn, connects
to my router and reboots it. I've had something very like it
for ages but
I've had a problem ever since a recent upgrade to RH7.2.
Basically, the script works fine in the foreground; it works fine under "at now +1 minute"; it works fine under "batch" BUT it always fails when run under cron.
The relevant output from failed jobs looks like:
spawn telnet my-router Trying 192.168.0.254... Connected to my-router. Escape character is '^]'.
Password: Connection closed by foreign host. send: spawn id exp3 not open while executing "exp_send -s -- $arg" (procedure "send" line 3) invoked from within "send -- "X"" (file "/usr/local/sbin/reboot_router.exp" line 53)
which seems to show that the telnet session is spawned OK and opens the connection (the "Password: " string comes from the router) but then as soon as expect tries to send the first character of the
password, it finds
that the telnet session has been closed!
Any ideas, please?
PS. Yes, I know all of the security risks in embedding passwords in scripts and in using telnet rather than ssh!