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. how to use multiple lines in executeSSHCommand ?

how to use multiple lines in executeSSHCommand ?

Scheduled Pinned Locked Moved Support
5 Posts 2 Posters 19.0k 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 trying to use SSH to push commands to devices through netXMS
    I'm using $node->executeSSHCommand to push commands, but how do I use multiple lines of text? I know on MikroTik I can separate commands with a semi-colon, i.e.

    $node->executeSSHCommand(":log warning test;:log warning test2;:log warning test3");
    

    This isn't viable for very long commands especially those with scripts in them that might be 50 lines or more. I can't compress them into a single line
    So how do I do something like....

    $node->executeSSHCommand("
    :log warning test
    :log warning test2
    :log warning test3
    ");
    

    Or even inside a variable

    MyBigScript = {
    :log warning test
    :log warning test2
    :log warning test3
    };
    $node->executeSSHCommand(MyBigScript);
    

    This syntax is not valid in NetXMS. So how do I do it? I need SSH scripts to be human readable and editable. Impossible with very long single liners

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

      I think I figured this out nope there's a problem, see next post

      $node->executeSSHCommand("log warning \"This is line1\"\n".
      "log warning \"This is line2\"\n".
      "log warning \"This is line3\"\n");
      

      Can also be parsed inside a string parameter. But the rules are

      1. all quotations to be parsed need to be escaped with a '\'
      2. the end of each line needs to have \n inside the quotations (otherwise they just continue on the same line i.e. "log warning This is line1log warning This is line2")
      3. each line needs to end with . to concatenate the lines together

      It's not the end of the world, but its a lot of manual manipulation of script files. Would be nice if I could just paste text blocks inside parenthesis but I imagine this is a limitation of NetXMS scripting language. If there is a better/cleaner method i'm all ears

      edit: to make life easy, in notepad++ paste the script then do the following...
      search->replace, pick extended mode
      1)
      find what: "
      Replace with: \"
      replace all

      find what: \r\n
      replace with: \\n".\r\n"
      replace all

      1. add (" to beginning of first line

      2. add "); to very last line

      Now copy/paste into NetXMS

      This is fast and effective enough for me, some of my scripts that I want to use NetXMS with are well over a hundred lines long. Doing this manually would have been a flapping nightmare

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

        So this has a problem. According to https://track.radensolutions.com/issue/NX-1649 I imagine the command 'executeSSHCommand' was implemented to get around the 1024 character limit is this correct? or is there another command? Since the bug tracker doesn't say which command was implemented

        But it seems there's actually a ~232 character limit on executeSSHCommand. At least I can't get it to run anything at all when I exceed that

        command = (":log info \"this is line01\"\n".
        ":log info \"this is line02\"\n".
        ":log info \"this is line03\"\n".
        ":log info \"this is line04\"\n".
        ":log info \"this is line05\"\n".
        ":log info \"this is line06111111111111111111\"\n".
        "");
        
        $node->executeSSHCommand(command);
        

        This is the longest possible string I can parse to the command, 1 character longer and nothing executes at all. Is this a bug or am I just doing this whole thing incorrectly?
        I have some scripts that are well over 2500 characters in length so this is a big problem

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

          Hi,

          unfortunately it is a limitation inside executeSSHCommand function implementation. I've added issue to fix it: https://track.radensolutions.com/issue/NX-2200

          Best regards,
          Victor

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

            Thanks, would be great if this was prioritized as this will massively enhance the potential of NetXMS. One of its greatest strengths for us is the ability to very rapidly run summary DCI's to get all sorts of useful information in a simple clean page. Being able to then select multiple nodes out of compliance and simply right click->tools->run SSH script to resolve issues or push mass config updates is very powerful

            Ideally i'd like to see further updates to SSH down the track, such as credentials list, config backups, diff notifications (against last, or template baseline). But for now a simple working SSH command execution would be niceĀ  ;D

            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