• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

perl to cisco connection

I want to let the do that ssh commands to the my cisco device how should i do it with perl ?

login as: root
root@ password:
force.salay.com.tr#configure terminal
force.salay.com.tr(conf)#ip route xx.xx.xx.xx null 0

Open in new window

1 Solution
Jordan MedlenCommented:
While perl can do this, I use expect scripts to perform various tasks. These scripts allow for automating various tasks based on received information and so forth.

For instance, portion of a script that logs into a Cisco edge device and checks connectivity to it's gateway...

    /usr/bin/expect <<EOF > /dev/null
    set timeout 10

    spawn ssh -q -o StrictHostKeyChecking=no $id@$ipaddr

    # First time, expect prompt for adding to known_hosts.
    expect {
        "Are you sure you want to continue connecting *" {
        send "yes\n"
        expect "*assword: "
        send "$pass\n"
        "*assword: " {
        send "$pass\n"

    expect "*>"
    send "en\r"
    expect "*assword: "
    send "$enpass\r"

    expect "*#"
    log_file /tmp/remote_ping-$checkip.txt
    send "ping $checkip\n"

    expect "*#"
    send "exit\n"


Open in new window

This can then be used within a bash or other script.

Google "expect examples for cisco devices" and you will find a great deal of information.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now