3 Replies Latest reply on May 29, 2014 6:06 AM by Fernando Castro Guti�rrez de Quevedo

    NSH: Use nexec, nohup and su in the same command

    Fernando Castro Guti�rrez de Quevedo

      Hi, I'm trying to implement a set of functions in NSH to be used from within BBSA projects.

       

      I have been asked to create a function that allows for using su for running the command as another user as well as nexec (for remote execution) and nohup for runing it in the background (Outputting to a custom, given file), all this using runcmd (If this looks stupid, you may want to meet the one who assigned this task to me )

       

      I'm having trouble in the below examples, which do not work at all. Note tht these are run sourcing a NSH script from "computer1":

       

      runcmd -h computer2.corp -e nohup "ls -al" > /tmp/nh1.txt 2> /tmp/nh2.txt < /dev/null &

      This creates both output files, but nh1.txt contains:

      ==> computer2.corp <==

      nohup: ls -al: No error

      Instead of the actual directory listing

       

       

      runcmd -h computer2.corp -e nexec -e su - root -c "nohup ls -l > /tmp/nh1.txt_2014-05-27_12-53-54 2> /tmp/nh2.txt_2014-05-27_12-53-55 < /dev/null & "

      The output of this is:

      ls: -c: line 0: unexpected EOF while looking for matching `"'

      ls: -c: line 1: syntax error: unexpected end of file

      ==> computer2.corp <==

       

      I'm very confused as this "project" has been around for ages with the lowest priority so no one is really sure of wht they want. In short, fi I can make the las command work, all I have to do then is create a wrapping function with a simple way to provide parameters, which I have already done.

       

      I hope you can help me out, thanks

        • 1. Re: NSH: Use nexec, nohup and su in the same command
          Bill Robinson

          i don't think you want to use runcmd or run script here - i think you should just nexec the su bit. 

          1 of 1 people found this helpful
          • 2. Re: NSH: Use nexec, nohup and su in the same command
            Fernando Castro Guti�rrez de Quevedo

            I'm trying this two commands (Directly via my local NSH Here and also sourcing a .nsh script from NSH Here) in computer1.corp, but to no avail:

             

             

            nexec computer2.corp nohup ls > /tmp/nh1.txt 2> /tmp/nh2.txt < /dev/null &

            This creates output files in computer1, stdout is empty and stderr says "nohup: ignoring input and appending output to `nohup.out'", file which is nowhere no be found: Not on computer1, nor computer2, nor my personal computer.

             

            nexec -e nohup ls > /tmp/nh1.txt 2> /tmp/nh2.txt < /dev/null &

            This creates both output files, however with the same message in stderr as above

             

            What am I doing wrong?

            • 3. Re: NSH: Use nexec, nohup and su in the same command
              Fernando Castro Guti�rrez de Quevedo

              I've learned about the -nohup parameter in nexec (Which I had no idea it existed), and have been trying to use it like this:

               

              (From computer2.corp) With and without su

              nexec -nohup computer1.corp "su -c '{ cd /; ls -al; whoami; }' test27  > /tmp/nh1.txt 2> /tmp/nh2.txt &"

              nexec -nohup computer1.corp "{ cd /; ls -al; whoami; } > /tmp/nh1.txt 2> /tmp/nh2.txt &"

               

              This seems to meet my current specifications -Including several commands at once- , though I will test it thoroughly to make sure. Once this is working, it's a matter of taking out the su bit if not needed as above and playing with the hostname if I wanted to execute it in localhost while maintaining the same syntax, which I have treied and works flawlessly. (This is going to be wrapped in a custom function taking parameters)

               

              I'll report any findings (Specially regarding Windows servers, which seem to need a tweak to this), but I think this is what I was looking for

              1 of 1 people found this helpful