Posted by neo (The Architect), 2 April 2005Hi all,
How do I write a expect script that will telnet to a remote machine and keep on checking if I am disconnected or not?
I want to reconnect as soon as I am disconnected.
How is this done?
Posted by admin (Graham Ellis), 2 April 2005How about "expect"ing an eof , and if you get one the reconnect?
Posted by neo (The Architect), 3 April 2005Tried that but after typing an exit on the remote machine I just get no prompt or anything.
Here is the code I used.
The code in the expect eof block is just for a test right now. It will be changed later to make it reconnect later.
Posted by neo (The Architect), 4 April 2005Does anyone have some example of this. I want to see how to send the commands after eof is received.
Posted by neo (The Architect), 4 April 2005Code:
Noe if I need to send some commands too while I am connected how do i do this. I mean I need the user to be able to be interact too (at least for a few commands).
How is this done?
Posted by admin (Graham Ellis), 5 April 2005on 04/04/05 at 14:54:06, The Architect wrote:
If you know want to send the commands automatically and analyse the responses automatically, then use send and expect commands. If you want to drop to keyboard input and display the response, then you can use the intereact command instead.
Posted by neo (The Architect), 5 April 2005Got that solved last night when I tried it out. Phew!
@Graham: Yeah I found that out with a little searching (in the man page). I sort of want to use both.
Anyway another doubt now.
I have a list of commands that I want to execute just after login. What kind of a loop can I use for this (some sample code would be nice) . I thought of storing the commands in a array and then usign that. How is this done in code?
Posted by admin (Graham Ellis), 5 April 2005on 04/05/05 at 12:48:18, The Architect wrote:
Well THANK YOU for letting me know before I put time into coming up with an answer
I appreciate that there are times you'll ask questions but then find out the answers elsewhere, but PLEASE have the decency to come back here and tell us that you've found an answer. I'm delighted to help people, but I don't have a lot of time and it's a bit of a slap in the face to put effort in for someone to have them say "oh - I got that answered elsewhere ...."
Posted by neo (The Architect), 6 April 2005on 04/05/05 at 14:52:54, Graham Ellis wrote:
Hey Man I really appreciate your help. In fact I also searched through this board and that was helpful.
Do you think I would not post here as soon as I get an answer? I did not have net access at that time (and I am in a place where I don't control that). I'm really sorry if you were offended.
Posted by admin (Graham Ellis), 6 April 2005I appreciate that not everyone has net access all the time. Shall we just say that this looks a little unfortunate. A question's asked, an answer found elsewhere within a very short time, and then other(s) spin their wheels looking for a solution while the original questioner goes off for a good night's sleep.
"Opentalk" is intended for questions that are difficult to get answered elsewhere. The format's not well suited to researching things where you have a number of active and parallel lines of enquiry all going on at the same time as (inevitably) incidents like this will happen. I appreciate your enthusiasm to ask, but can I suggest that you limit yourself to questions that you're very unlikely to get solved elsewhere in the very short term and that if you're lucky enough to solve them through another route after all you make a concerted effort to let us know, even if it means specially dialling in to post? That's a great way to help us help you.
Posted by neo (The Architect), 6 April 2005Whoops, had to read that twice slowly to get it.
And yes I will try to be more careful about posting things that I may be able to solve sooner or later.
And no I cannot dial in (absolutely prohibited in the wrong hours )
Posted by neo (The Architect), 21 May 2005I had written this script that keeps logging into the remote server even after I get disconnected.
It works fine but I've noticed that after a while the process seems to be killed because I see that I am out of the remote and the terminal shows this
Is there anything I have to do so that I am always connected and this script process is not killed?
Posted by admin (Graham Ellis), 21 May 2005I suspect that the remote machine has been set up to guard against automated access and recognises it in various ways (e.g. timeouts, allowing for connections for only a certain proportion of the time, etc). So you're probably going to have to play a game of "cat and mouse" in order to maintain your connection.
I always have a slightly uneasy feeling when someone's writing software to "spoof" a remote system to allow then to remain connected ... is it OK with the remote machine's administrator that you're handing on in this way? If so, could he/she provide you with an easier form of access that doesn't time out? There's more than one way to catch a crockodile, you know
Posted by neo (The Architect), 21 May 2005No I have absolute access on the remote machine (root). I think my local sys kills the process after some time. Is there any way to verify and guard against this?
Posted by admin (Graham Ellis), 23 May 2005on 05/21/05 at 17:00:31, The Architect wrote:
That sounds like it's a local operating system issue
Posted by neo (The Architect), 23 May 2005Yeah is there anything I can do about this?
If i start this in the background will this be avoided?
Posted by admin (Graham Ellis), 23 May 2005It's an operating system matter - it depends on what operating system you're using, which command line interpretter ("shell") and what parameters / settings you have. You'll probably find you can find an answer in the documentation for that operating system, or on chat rooms / forums that are OS specific rather than here, which is language specific.
I would expect (please excuse that pun - it's hard to avoid) that i fyou run your process as a daemon or service you might be in luck - but you do need to ensure that the settings percolate through to your spawned process.
Posted by neo (The Architect), 23 May 2005Ok thanks. I'll try that.
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho