Rancid For HP, H3C & Huawei Switches

It took me times to research and find out how to get configuration backup automatically from H3C, Huawei and HP network devices. Finally I can get it works using Rancid with the following steps. But wait, if you don’t understand what Rancid is, check out our Rancid article.

Before we move ahead to the heart of the article, I would like to mention that this document is specifically for Rancid version 2 and below platform/models have been tested successfully.

  • Huawei MA5600 (Comware 5)
  • HP A5900 (Comware 7)
  • H3C S3100 (Comware 3)
  • H3C S5600 (Comware 3)
  • H3C S7506 (Comware 5)
  • H3C S7906E (Comware 5)
  • H3C S5820X / HP A5800-48G (Comware 5)
  • H3C S5800 (Comware 5)
  • H3C S3610 (Comware 5)
  • H3C MSR30-60 (Comware 5)
  • H3C/HP S5120 (Comware 5)
  • 3Com 7750 (Comware 3)
  • 3Com 5500-EI/SI / HP E5500-EI/SI (Comware 3)
  • 3Com 5500G (Comware 3)
  • 3Com 4200G (Comware 3)
  • 3Com 4210 (Comware 3)
  • 3Com 4800G / H3C S5500 / HP A5500 (Comware 5)
  • 3Com 4210G (Comware 5)

1. Upload scripts to Rancid server (h3clogin & h3crancid script has been attached)

In my case, I have customized Rancid path to /rancid/bin/ so if you are using different path, you have to upload both files attached there.

2. Change files permission and ownership

After the files are uploaded, you have to change permission and ownership with following command.

chown rancid:netadm /rancid/bin/h3clogin
chown rancid:netadm /rancid/bin/h3crancid
chmod 755 /rancid/h3clogin
chmod 755 /rancid/h3crancid

3. Modify rancid-fe file in the same directory

As I mentioned above, I have Rancid in /rancid/ so now I have to modify rancid-fe file in order to get it support with H3C. The command would be:

vim /rancid/bin/rancid-fe

Then add the following line. There are similar setting for different vendor in that file.

'h3c' => 'h3crancid',

4. Create Rancid Group

It is very useful to separate different network devices’ configuration by using different directory. It can be based on customer name, geographical location or vendor platform.

In order to do that, you have to modify /rancid/etc/rancid.conf by adding the name of the group. Below is the example of creating Test group where all the device configurations will be stored.

LIST_OF_GROUP="Test"

!!Other example

LIST_OF_GROUP="Australia USA England"

The group names must be separated with a space.
Once a new group is added you need to generate config and svn folder with below command:

rancid-cvs

5. Email aliases need to be created

Now it is time to put in an email address to receive notification whenever configuration on the network devices change.

vim /etc/aliases
rancid-admin-Test:   rancid-Test
rancid-Test:         noc
noc:                 [email protected]

6. Add H3C switch into router.db

Now you have to add your H3C switch into router.db file so that Rancid can keep trace on it.

vim /rancid/var/Test/router.db
MyDevice:h3c:up

7. Update the hosts file

Note that MyDevice that has been added in router.db above, we have to map it with an IP address in hosts file.

vim /etc/hosts

!!Below is an example of MyDevice IP address

192.168.0.1     MyDevice

8. Add login credential of device to .cloginrc file

Rancid uses Telnet or SSH to log into network devices and pull the configuration then compare for differ. So we have to add login credential other it wont work.

!!!Recommendation: I would suggest to create a separate username and password with read-only permission.

vim .cloginrc

Then modify the .cloginrc file with something similar as the following.

add user      MyDevice username-to-login
add password  MyDevice password-to-login
add method    MyDevice ssh

9. Login Verification

Now let test if you can login to your H3C switch with Rancid. You will need to troubleshoot it if you cannot login successfully before you move to the next step.

[[email protected] ~]$ h3clogin MyDevice

10. Let get the configuration from the switch

!!!Before you issue below command, make sure you are rancid user otherwise the permission of configuration file will be changed and cause some issue when it automatically run.

[[email protected] ~]$ rancid-ran Test

Note that you can issue above command for specific group or just rancid-ran for every groups in the system. The configuration file will be stored at /rancid/var/Test/config/

That’s it!!! Now you can get configuration for H3C, HP, H3Com and Huawei switch using Rancid or leave a comment below if have an issue.

Download the files, simply click the link below.

h3crancid              h3clogin

9 Replies to “Rancid For HP, H3C & Huawei Switches”

  1. Hello. I am trying to use your script but it doesn’t work for me.
    /usr/local/rancid/bin/h3clogin -t 20 -c”display current-configuration” x.x.x.x this script runs perfectly, but while am trying this, error appears

    /usr/local/rancid/bin/h3crancid -d x.x.x.x
    executing /usr/local/rancid/bin/h3clogin -t 20 -c”display current-configuration” x.x.x.x
    10.0.1.148 /usr/local/rancid/bin/h3clogin error: Error: Unrecognized command found at ‘^’ position.
    10.0.1.148 /usr/local/rancid/bin/h3clogin error: Error: Unrecognized command found at ‘^’ position.
    10.0.1.148: clean_run=0 found_end=0
    10.0.1.148: missed cmd(s): display current-configuration
    10.0.1.148: missed cmd(s): display current-configuration
    10.0.1.148: End of run not found
    10.0.1.148: End of run not found

    Please, help

    1. Hi Misha,

      Thanks for dropping us a comment. We dont have any H3C switch to test at the moment, but We will check with few friends and will let you know asap.

      Regards,
      iNET9 Admin

  2. Hi admin, thanks for the scripts. I’m getting an error too when trying to execute:

    /opt/rancid/bin$ /opt/rancid/bin/h3crancid -d hrouter

    executing /opt/rancid/bin/h3clogin -t 20 -c”display current-configuration” hrouter
    hrouter /opt/rancid/bin/h3clogin error: Error: Wrong parameter found at ‘^’ position.
    hrouter /opt/rancid/bin/h3clogin error: Error: Wrong parameter found at ‘^’ position.
    write(spawn_id=1): broken pipe
    while executing
    “send_user — “$expect_out(buffer)””
    invoked from within
    “expect -nobrace -re+ { exp_continue } -re {^[^
    *]*} { send_user — “$expect_out(buffer)”
    } -re {^[^
    ]*.} { send_user –…”
    invoked from within
    “expect {
    -re “\b+” { exp_continue }
    -re “^\[^\n\r *]*$reprompt” { send_user — “$expect_out(buffer)”
    }
    -re “^\[^\n\r]*$reprompt.” { send…”
    (procedure “run_commands” line 25)
    invoked from within
    “run_commands $prompt $command”
    (“foreach” body line 220)
    invoked from within
    “foreach router [lrange $argv $i end] {
    set router [string tolower $router]
    # attempt at platform switching.
    set platform “”
    send_user …”
    (file “/opt/rancid/bin/h3clogin” line 708)
    hrouter: clean_run=0 found_end=0
    hrouter: missed cmd(s): display current-configuration
    hrouter: missed cmd(s): display current-configuration
    hrouter: End of run not found
    hrouter: End of run not found

    Maybe you can help out with this issue.
    Kind regards

  3. Dear Admin,

    Do you have any new update for new Huawei devices? Because this Comware work only with old version of Huawei device.
    Please help to assist on this.

  4. This script does not work for huawey

    wrong # args: should be “set varName ?newValue?”
    while executing
    “set do_command 0 set do_script 0”
    (file “/var/lib/rancid/bin/h3clogin” line 57)

  5. hi all,

    I got this error while rancid-run is running. Any solution for this ?

    #/var/logs$ cat INTERNAL.20181115.170913
    starting: Thu Nov 15 17:09:13 WIB 2018

    Trying to get all of the configs.
    unknown router manufacturer for atn-xxxxxxxxxxxx: h3c
    =====================================
    Getting missed routers: round 1.
    unknown router manufacturer for atn-xxxxxxxxxxxx: h3c
    =====================================
    Getting missed routers: round 2.
    unknown router manufacturer for xxxxxxxxxxxx: h3c
    =====================================
    Getting missed routers: round 3.
    unknown router manufacturer for atn-xxxxxxxxxxxx: h3c
    =====================================
    Getting missed routers: round 4.
    unknown router manufacturer for atn-xxxxxxxxxxxx: h3c

    cvs diff: Diffing .
    cvs diff: Diffing configs
    cvs commit: Examining .
    cvs commit: Examining configs

    ending: Thu Nov 15 17:09:13 WIB 2018

Leave a Reply

Your email address will not be published. Required fields are marked *