Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. Example of how to setup SSH script/commands?

Example of how to setup SSH script/commands?

Scheduled Pinned Locked Moved Support
5 Posts 3 Posters 24.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M
    M
    Millenium7
    wrote on last edited by
    #1

    I'm slowly getting more comfortable with NetXMS but unfortunately it can be difficult to find out how to actually implement things at times 😞 One of these is how to send SSH commands to a device. I've googled and seen this is possible but I can't find any actual examples to help set it up

    I want to be able to be able to send commands via SSH to a device. A simple example being I have created a DCI summary table to show MikroTik RouterOS versions. I want to be able to select all that are outdated, right click, choose Tools->MikroTik Commands->Update RouterOS
    And in the background NetXMS would connect to the device with SSH and execute '/system package update install'

    How do I set this up?
    Then once I get the basics working, is it possible to parse more advanced commands via SSH? I.e. using variables so I could choose 'Update RouterOS' but specify a time as a variable and it would send
    '/system scheduler add on-event="/system package update install" start-time=$NetXMSTimeVariable'
    So the device would update at 3:30am instead of immediately

    1 Reply Last reply
    0
    • V
      V
      Victor Kirhenshtein
      wrote on last edited by
      #2

      Hi,

      you can use NXSL script and function AgentReadList like this:

      AgentReadList($node, "SSH.Command(mikrotik_ip,login,password,/system package update install)");
      

      where $node is a node with SSH subagent installed. Of course you can use string concatenation to insert proper credentials and device IP address. For example, if variable $node points to NetXMS server node and variable mt to Mikrotik device, you can do

      AgentReadList($node, "SSH.Command(" . mt->ipAddr . ",login,password,/system package update install)");
      

      Best regards,
      Victor

      1 Reply Last reply
      0
      • M
        M
        Millenium7
        wrote on last edited by
        #3

        Only agent is the NetXMS server itself, so can I just use 127.0.0.1 for the node?
        And how about longer commands with multiple lines? I have some custom scripts that are 50 lines long, impossible to put them into a single line

        1 Reply Last reply
        0
        • V
          V
          Victor Kirhenshtein
          wrote on last edited by
          #4

          Yes, but you have to use node object here, not IP address. You can use FindObject or FindNodeObject functions to get object by name.

          Longer commands are not possible without agent and/or server modifications. Currently there is 1024 character limit on parameter length in AgentRead... functions.

          I've also created couple of feature requests for SSH improvements:
          https://track.radensolutions.com/issue/NX-1649
          https://track.radensolutions.com/issue/NX-1650

          Best regards,
          Victor

          1 Reply Last reply
          0
          • E
            E
            Egert143
            wrote on last edited by
            #5

            Hello

            Millenium7, did you get ssh script working ? I could use some examples also, how to get basic ssh commands working.

            Egert

            1 Reply Last reply
            0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            Powered by NodeBB Contributors
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups