Re: script to log into cisco csm load balancer

From: shiran guez (shiranp3@gmail.com)
Date: Thu Jan 22 2009 - 19:16:21 ARST


As I say don't "expect" too much :-)

On Thu, Jan 22, 2009 at 7:36 PM, Tyson Scott <tscott@ipexpert.com> wrote:

> testing,
>
> I am going to have to do a little defending here ;-) There is nothing more
> simple and powerful than expect in network administration. There is a
> reason Cisco put TCL on the routers. And expect is an extension/improvement
> upon TCL. The downfall of expect, (I will admit), is there are not a lot of
> good examples out there on it and there is only one reference book, written
> by Don Libes (The person that developed expect). Over half the people that
> use expect aren't even familiar with how powerful of a tool it is.
>
>
>
> #!/usr/bin/expect
>
>
>
> spawn telnet <hostname>
>
> expect {
>
> "Username:" {
>
> send "<username>\r"
>
> exp_continue
>
> }
>
> "Password:" {
>
> send "<password>\r"
>
> exp_continue
>
> }
>
> ">" {
>
> send "enable\r<enablepass>\r"
>
> exp_continue
>
> }
>
> "#" {
>
> send "show ip interface brief | exclude
> unav\r"
>
> expect "show ip interface brief | exclude
> unav"
>
> expect "#" { send "exit\r" }
>
> expect "Connection closed by foreign host"
>
> }
>
> expect eof
>
>
>
> I have shown a very brief and simple expect script. You can build in a lot
> more error checking functionality into this that would greatly improve the
> functionality of the script. As is seen it will continue to loop thru
> username/password until it gets to the enable prompt and then it will issue
> the commands needed.
>
>
>
> Regards,
>
>
>
> Tyson Scott - CCIE #13513 R&S and Security
>
> Technical Instructor - IPexpert, Inc.
>
>
> Telephone: +1.810.326.1444
> Cell: +1.248.504.7309
> Fax: +1.810.454.0130
> Mailto: tscott@ipexpert.com
>
>
>
>
>
> *From:* shiran guez [mailto:shiranp3@gmail.com]
> *Sent:* Thursday, January 22, 2009 11:02 AM
> *To:* Tyson Scott
> *Cc:* testing testing123; ccielab@groupstudy.com
> *Subject:* Re: script to log into cisco csm load balancer
>
>
>
> I use python as it is more flexible then expect and much easy syntax then
> perl here is an real small exmple but you can actually do what you described
> you need in not much more code lines:
>
> ============================================================
>
> #!/usr/bin/python
>
>
>
> import getpass
> import sys
> import telnetlib
>
>
>
> HOST = raw_input("Enter your remote address: ")
> user = "user"
> password = "pass"
> enable = "enapass"
>
> tn = telnetlib.Telnet(HOST)
>
> tn.read_until("Username: ")
> tn.write(user + "\n")
> if password:
> tn.read_until("Password: ")
> tn.write(password + "\n")
>
> tn.write("enable\n")
> if password:
> tn.read_until("Password: ")
> tn.write(enable + "\n")
> tn.write("show ip int b | ex una\n")
> tn.write("exit\n")
>
> print tn.read_all()
>
> ========================================================
>
>
>
>
>
> Good luck
>
> On Wed, Jan 21, 2009 at 1:02 AM, Tyson Scott <tscott@ipexpert.com> wrote:
>
> Perl or Expect will provide you the greatest functionality and
> customization
> in my opinion. Perl has a lot more examples that you can easily obtain off
> of the internet. Expect is a great tool for network admins.
>
> Regards,
>
> Tyson Scott - CCIE #13513 R&S and Security
> Technical Instructor - IPexpert, Inc.
>
> Telephone: +1.810.326.1444
> Cell: +1.248.504.7309
> Fax: +1.810.454.0130
> Mailto: tscott@ipexpert.com
>
>
>
> -----Original Message-----
> From: nobody@groupstudy.com [mailto:nobody@groupstudy.com] On Behalf Of
> testing testing123
> Sent: Tuesday, January 20, 2009 5:27 PM
> To: ccielab@groupstudy.com
> Subject: script to log into cisco csm load balancer
>
> What language should I use to write a script to log into my cisco csm
> load balancer and check the usage ? The place I work for doesn't have
> any industry tools like HP Openview, CIscoworks, solarwinds, or
> anything like that. I want it to log into the csm once every half
> hour and check the connections of the serverfarms and export it to a
> spreadsheet that will automatically graph that data.
>
> thanks
>
>
> Blogs and organic groups at http://www.ccie.net
>
> _______________________________________________________________________
> Subscription information may be found at:
> http://www.groupstudy.com/list/CCIELab.html
>
>
> Blogs and organic groups at http://www.ccie.net
>
> _______________________________________________________________________
> Subscription information may be found at:
> http://www.groupstudy.com/list/CCIELab.html
>
>
>
>
>
>
>
>
>
> --
> Shiran Guez
> MCSE CCNP NCE1 JNCIA-ER CCIE #20572
> http://cciep3.blogspot.com
> http://www.linkedin.com/in/cciep3
>

-- 
Shiran Guez
MCSE CCNP NCE1 JNCIA-ER CCIE #20572
http://cciep3.blogspot.com
http://www.linkedin.com/in/cciep3

Blogs and organic groups at http://www.ccie.net



This archive was generated by hypermail 2.1.4 : Sun Mar 01 2009 - 09:43:39 ARST