all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* telnet in buffer using elisp -- is this the best way?
@ 2004-07-10 18:44 Tennis Smith
  2004-07-10 21:51 ` Kai Grossjohann
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Tennis Smith @ 2004-07-10 18:44 UTC (permalink / raw)


Hi

Apologies for the basic nature of the questions, but my area is s/w testing,
not elisp writing. ;-)

I frequently have the need to telnet into routers, via console ports thru a
term server or a native ip address.  I've built some *very* basic elisp
functions for doing this, but I'm wondering if there is a better way. The
number of routers in my environment continues to grow (Im in a testing
group, we have hundreds of the things). So, this approach has become a real
problem since each router requires a separate function to access it.

Here are a couple examples:

(defun 5gw-con ()
(interactive)
(telnet "10.10.10.58 2008")
(rename-buffer "ef-gw-5-con"))

(defun 5gw-con2 ()
(interactive)
(telnet "10.10.10.58 2009")
(rename-buffer "ef-gw-5-con"))

(defun 7gw ()
(interactive)
(telnet "10.10.10.40")
(rename-buffer "ef-gw-7"))

There's an additional issue too. Sometimes the same address will be used in
multiple places. Note that the first two examples uses an ip/port
combination. In this case the port will be changing, but the base ip address
will stay the same. Is there a way to specify the ip address in _one_ place
and have it be used in multiple places?

Is there a better way to do all this?

TIA,
-Tennis




--
Remove "-remove-to-reply" to respond to my  email address directly.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: telnet in buffer using elisp -- is this the best way?
  2004-07-10 18:44 telnet in buffer using elisp -- is this the best way? Tennis Smith
@ 2004-07-10 21:51 ` Kai Grossjohann
  2004-07-10 22:24 ` Kin Cho
  2004-07-13  7:59 ` Tim X
  2 siblings, 0 replies; 6+ messages in thread
From: Kai Grossjohann @ 2004-07-10 21:51 UTC (permalink / raw)


"Tennis Smith" <tennis_smith@yahoo-remove-to-reply.com> writes:

> There's an additional issue too. Sometimes the same address will be used in
> multiple places. Note that the first two examples uses an ip/port
> combination. In this case the port will be changing, but the base ip address
> will stay the same. Is there a way to specify the ip address in _one_ place
> and have it be used in multiple places?
>
> Is there a better way to do all this?

Perhaps this approach works: you define an alist which you then use
for completion.  The keys of the alist are names, the values are
strings to pass to telnet.

(defvar tennis-routers
        '(("one" "10.10.10.1" 42)))

(defun tennis-telnet (router)
  (interactive
    (list (completing-read "Router: " tennis-routers)))
  ;; At this point, router is a string.  We make it the complete
  ;; entry in tennis-routers.
  (setq router (assoc router tennis-routers))
  (telnet (nth 1 router) (nth 2 router))
  (rename-buffer (nth 0 router)))

I haven't tested it.

Kai

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: telnet in buffer using elisp -- is this the best way?
  2004-07-10 18:44 telnet in buffer using elisp -- is this the best way? Tennis Smith
  2004-07-10 21:51 ` Kai Grossjohann
@ 2004-07-10 22:24 ` Kin Cho
  2004-07-11  1:34   ` Tennis Smith
  2004-07-13  7:59 ` Tim X
  2 siblings, 1 reply; 6+ messages in thread
From: Kin Cho @ 2004-07-10 22:24 UTC (permalink / raw)


"Tennis Smith" <tennis_smith@yahoo-remove-to-reply.com> writes:

> Hi
> 
> Apologies for the basic nature of the questions, but my area is s/w testing,
> not elisp writing. ;-)

I doubt anybody's area is elisp writing -- except for the
full-time emacs people at gnu.

> I frequently have the need to telnet into routers, via console ports thru a
> term server or a native ip address.  I've built some *very* basic elisp
> functions for doing this, but I'm wondering if there is a better way. The
> number of routers in my environment continues to grow (Im in a testing
> group, we have hundreds of the things). So, this approach has become a real
> problem since each router requires a separate function to access it.
> 
> Here are a couple examples:
> 
> (defun 5gw-con ()
> (interactive)
> (telnet "10.10.10.58 2008")
> (rename-buffer "ef-gw-5-con"))
> 
> (defun 5gw-con2 ()
> (interactive)
> (telnet "10.10.10.58 2009")
> (rename-buffer "ef-gw-5-con"))
> 
> (defun 7gw ()
> (interactive)
> (telnet "10.10.10.40")
> (rename-buffer "ef-gw-7"))

The code below creates these functions based on a table:

(mapc
 (lambda (x)
   (fset (car x) 
	 (list 'lambda () (nth 1 x) '(interactive)
	       (nth 1 x) `(telnet ,(nth 1 x)) `(rename-buffer ,(nth 2 x)))))
 '((5gw-con "10.10.10.58 2008" "ef-gw-5-con")
   (5gw-con2 "10.10.10.58 2009" "ef-gw-5-con2")
   (7gw "10.10.10.40" "ef-gw-7")))

You should M-: (info " (elisp) Top") if you want to find out how
the above works.

-kin

> 
> There's an additional issue too. Sometimes the same address will be used in
> multiple places. Note that the first two examples uses an ip/port
> combination. In this case the port will be changing, but the base ip address
> will stay the same. Is there a way to specify the ip address in _one_ place
> and have it be used in multiple places?
> 
> Is there a better way to do all this?
> 
> TIA,
> -Tennis
> 
> 
> 
> 
> --
> Remove "-remove-to-reply" to respond to my  email address directly.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: telnet in buffer using elisp -- is this the best way?
  2004-07-10 22:24 ` Kin Cho
@ 2004-07-11  1:34   ` Tennis Smith
  2004-07-11  8:25     ` Kai Grossjohann
  0 siblings, 1 reply; 6+ messages in thread
From: Tennis Smith @ 2004-07-11  1:34 UTC (permalink / raw)


Hi Kin,

Thanks for the response. I like the approach. Couple additional questions
below.

-Tennis

<snip>
>
> (mapc
>  (lambda (x)
>    (fset (car x)
> (list 'lambda () (nth 1 x) '(interactive)
>        (nth 1 x) `(telnet ,(nth 1 x)) `(rename-buffer ,(nth 2 x)))))
>  '((5gw-con "10.10.10.58 2008" "ef-gw-5-con")
>    (5gw-con2 "10.10.10.58 2009" "ef-gw-5-con2")
>    (7gw "10.10.10.40" "ef-gw-7")))

How can I stuff the 10.10.10.58 addr in to variable so I only have to change
it in one place?
>
> You should M-: (info " (elisp) Top") if you want to find out how
> the above works.

Hmmm... I got "no match" on my machine for this. I typed:

alt-x
followed by:

: (info " (elisp) Top")

Maybe I'm misunderstanding what you're saying....
>
> -kin
>
<snip>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: telnet in buffer using elisp -- is this the best way?
  2004-07-11  1:34   ` Tennis Smith
@ 2004-07-11  8:25     ` Kai Grossjohann
  0 siblings, 0 replies; 6+ messages in thread
From: Kai Grossjohann @ 2004-07-11  8:25 UTC (permalink / raw)


"Tennis Smith" <tennis_smith@yahoo-remove-to-reply.com> writes:

>> You should M-: (info " (elisp) Top") if you want to find out how
>> the above works.
>
> Hmmm... I got "no match" on my machine for this. I typed:
>
> alt-x
> followed by:

M-: and M-x are two different keys.

Kai

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: telnet in buffer using elisp -- is this the best way?
  2004-07-10 18:44 telnet in buffer using elisp -- is this the best way? Tennis Smith
  2004-07-10 21:51 ` Kai Grossjohann
  2004-07-10 22:24 ` Kin Cho
@ 2004-07-13  7:59 ` Tim X
  2 siblings, 0 replies; 6+ messages in thread
From: Tim X @ 2004-07-13  7:59 UTC (permalink / raw)


>>>>> "Tennis" == Tennis Smith <tennis_smith@yahoo-remove-to-reply.com> writes:

 Tennis> Hi Apologies for the basic nature of the questions, but my
 Tennis> area is s/w testing, not elisp writing. ;-)

 Tennis> I frequently have the need to telnet into routers, via
 Tennis> console ports thru a term server or a native ip address.
 Tennis> I've built some *very* basic elisp functions for doing this,
 Tennis> but I'm wondering if there is a better way. The number of
 Tennis> routers in my environment continues to grow (Im in a testing
 Tennis> group, we have hundreds of the things). So, this approach has
 Tennis> become a real problem since each router requires a separate
 Tennis> function to access it.

 Tennis> Here are a couple examples:

 Tennis> (defun 5gw-con () (interactive) (telnet "10.10.10.58 2008")
 Tennis> (rename-buffer "ef-gw-5-con"))

 Tennis> (defun 5gw-con2 () (interactive) (telnet "10.10.10.58 2009")
 Tennis> (rename-buffer "ef-gw-5-con"))

 Tennis> (defun 7gw () (interactive) (telnet "10.10.10.40")
 Tennis> (rename-buffer "ef-gw-7"))

 Tennis> There's an additional issue too. Sometimes the same address
 Tennis> will be used in multiple places. Note that the first two
 Tennis> examples uses an ip/port combination. In this case the port
 Tennis> will be changing, but the base ip address will stay the
 Tennis> same. Is there a way to specify the ip address in _one_ place
 Tennis> and have it be used in multiple places?

 Tennis> Is there a better way to do all this?

Well, just off the top of my head -

I would maintain a text file something like
router_name ip:port

Then I'd generalize my function so that it takes a single argument -
the router name and have the function obtain the ip address (possibly
with port spec) from the lookup file. You have only one function and a
lookup file to maintain.

tim





 Tennis> -- Remove "-remove-to-reply" to respond to my email address
 Tennis> directly.



-- 
Tim Cross
The e-mail address on this message is FALSE (obviously!). My real e-mail is
to a company in Australia called rapttech and my login is tcross - if you 
really need to send mail, you should be able to work it out!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-07-13  7:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-10 18:44 telnet in buffer using elisp -- is this the best way? Tennis Smith
2004-07-10 21:51 ` Kai Grossjohann
2004-07-10 22:24 ` Kin Cho
2004-07-11  1:34   ` Tennis Smith
2004-07-11  8:25     ` Kai Grossjohann
2004-07-13  7:59 ` Tim X

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.