Kaseya Community

Router config backup script query

This question has suggested answer(s)

Hi there,

Firstly, I am very new to Kaseya and to scripting. I'm one month in for both.

I need to create a procedure that will output and save the running config of cisco routers. We have a number of these at client sites. I have created a very simple batch file that uses plink to login to the routers and output the config to a .txt file.

If I run this file on the server it works fine.

If I try to run the batch file using executeshellcommand  I get an empty output file.

If I run plink using executefile and add the Kaseya shows me a failed loading message.

The command line I am using is as follows  - "d:\path\plink.exe ipaddress  -ssh -l user -pw password en sho run > d:\path\output.txt"

Setting up ftp or tftp servers at each site to back up the configs to is not possible.

I realise that I am probably missing lots of lovely problem fixing code, however after a number of hours of testing, I thought it was time to admit defeat and ask for some expert help. If anyone can help it would be really appreciated.

Many thanks.



[edited by: Dcomd at 4:50 PM (GMT -7) on Jun 11, 2013] changed to q
All Replies
  • Hi,

    In the command line try using the >> instead of > to output the data.

  • Offhand, my first thought would go back to my previous experience with putty and plink.  The first time you connect to an SSH server, it prompts you to accept the private key, and then stores that in your user profile.  Keep in mind that when you run things from a kaseya proceedure it runs as the "System" user by default.    My guess is that it's failing to actually do anything when run as system because it's trying to prompt you to accept the key.  My first suggestion, though I can't really test it from where I am right now, would be to add the -batch argument to the plink command line as that specifically disables all interactive prompts.

    I'm not 100% certain that is what is going on, but it's my first guess.  The other option would be to "use credentials" to specifically get your script to run as a specific user and ensure you have accepted the key previously.

  • I had a chance to do a little testing of my own this afternoon, and confirmed that my guess is most likely what is happening to you... If you run plink against an "unknown" ssh host even *with* the bacth option, it results in a prompt

    The server's host key is not cached in the registry. You
    have no guarantee that the server is the computer you
    think it is.
    The server's rsa2 key fingerprint is:
    blah blah blah...
    If you trust this host, enter "y" to add the key to
    PuTTY's cache and carry on connecting.
    If you want to carry on connecting just once, without
    adding the key to the cache, enter "n".
    If you do not trust this host, press Return to abandon the
    connection.
    Store key in cache? (y/n) Connection abandoned.

    So when you are running non-interactively it cannot accept the connection.  The host keys are stored in the 'HKEY_CURRENT_USER' registry, so it's definately user profile specific.   Thus far I haven't found a way to import that to the "System" profile, so you would almost certainly have to run the command as a specific user who has the host key already in their profile.

     

     

     

  • Hi there,

    Thanks for the replies.

    I had success at the end of yesterday afternoon and the solution used the suggestions above and some other google based bits...

    - Login into the server that will run plink and manually connect to each router via plink and store the RSA key when prompted

    - Use the ImpersonateUser command to run plink as the same user as above. Plink will then be able to read the key

    - Use >> instead of > when redirecting output

    - Add 2>>&1 to the end of the command line to capture errors. This showed me that I...

    - Needed to put extra quotes around my command line as there were spaces in my path names

    Once all the pieces were put together, boom.

    Again, thanks for all the help.



    [edited by: Dcomd at 3:59 PM (GMT -7) on Jun 13, 2013] spelling mistakes