1 2 Previous Next 16 Replies Latest reply on Nov 24, 2014 11:15 AM by Joe Haley

    How to execute a VBScript content through NSH script

    Naren S

      Hi,

       

      Can someone explain how to execute a VBScript content through NSH script, I want to execute the VBScript centrally from BL appserver parsing the server list using h% option.

       

      Thanks,

      Surendar

        • 1. Re: How to execute a VBScript content through NSH script
          Ashitosh Wagh

          Hi Surendar,

           

          you can try this :

           

          DIR="/c/Program Files (x86)/BladeLogic/OM/share/custom"

          script=OVO_MGMT.vbs

          TARGET=$(uname -n)

           

          cd "$DIR"

           

          pwd

           

          cp $script//$TARGET/tmp

           

          cd //$TARGET/tmp

           

          RN=`nexec -e cscript \/nologo $script`

           

          Thanks

          Ashitosh

          • 2. Re: How to execute a VBScript content through NSH script
            Bill Robinson

            or you can make it self-contained like this:

             

            #!/bin/nsh

            FULL_PATH_THIS_FILE="$0"
            THIS_FILE=`basename "${FULL_PATH_THIS_FILE}"`

            # Find location of embedded script
            LENGTH_OF_MAIN_SCRIPT=`cat "$FULL_PATH_THIS_FILE" | grep -n '### END OF MAIN SCRIPT ###' | grep -v grep | cut -d ':' -f1`

            # Increment this by one to move past the line identifier
            LENGTH_OF_MAIN_SCRIPT=`expr $LENGTH_OF_MAIN_SCRIPT + 1`

            # Extract Script
            tail +$LENGTH_OF_MAIN_SCRIPT "$FULL_PATH_THIS_FILE" > "/tmp/$$"

            for target in ${@}
            do
            cp /tmp/$$ //${target}/tmp/$$.vbs
            nexec -i -l ${target} cmd /c "cscript /nolog c:\\\tmp\\\$$.vbs"
            rm -f //${target}/tmp/$$.vbs
            done
            rm -f /tmp/$$
            exit 0

            ### END OF MAIN SCRIPT ###
            PUT SOME VB HERE

            • 3. Re: How to execute a VBScript content through NSH script
              Naren S

              Hi Bill,

               

              This self-contained NSH script is not working, but when i execute the vbscript locally in the target server, there was no issue. Below is the NSH script which i used for NSH script job and i used the script type "Execute the script seperately against each host, using runscript" option.

               

              #!/bin/nsh

              FULL_PATH_THIS_FILE="$0"
              THIS_FILE=`basename "${FULL_PATH_THIS_FILE}"`

              # Find location of embedded script
              LENGTH_OF_MAIN_SCRIPT=`cat "$FULL_PATH_THIS_FILE" | grep -n '### END OF MAIN SCRIPT ###' | grep -v grep | cut -d ':' -f1`

              # Increment this by one to move past the line identifier
              LENGTH_OF_MAIN_SCRIPT=`expr $LENGTH_OF_MAIN_SCRIPT + 1`

              # Extract Script
              tail +$LENGTH_OF_MAIN_SCRIPT "$FULL_PATH_THIS_FILE" > "/tmp/$$"

              for target in ${@}
              do
              cp /tmp/$$ //${target}/tmp/$$.vbs
              nexec -i -l ${target} cmd /c "cscript /nolog c:\\\tmp\\\$$.vbs"
              rm -f //${target}/tmp/$$.vbs
              done
              rm -f /tmp/$$
              exit 0

              ### END OF MAIN SCRIPT ###

               

              Option Explicit

              const strComputer = "."
              const strReport = "c:\diskspace.txt"


              Dim objWMIService, objItem, colItems
              Dim strDriveType, strDiskSize, txt

              Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
              Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType=3")
              txt = "Drive" & vbtab & "Size" & vbtab & "Used" & vbtab & "Free" & vbtab & "Free(%)" & vbcrlf
              For Each objItem in colItems

               

              DIM pctFreeSpace,strFreeSpace,strusedSpace

               

              pctFreeSpace = INT((objItem.FreeSpace / objItem.Size) * 1000)/10
              strDiskSize = Int(objItem.Size /1073741824) & "Gb"
              strFreeSpace = Int(objItem.FreeSpace /1073741824) & "Gb"
              strUsedSpace = Int((objItem.Size-objItem.FreeSpace)/1073741824) & "Gb"
              txt = txt & objItem.Name & vbtab & strDiskSize & vbtab & strUsedSpace & vbTab & strFreeSpace & vbtab & pctFreeSpace & vbcrlf

              Next

              writeTextFile txt, strReport
              wscript.echo "Report written to " & strReport & vbcrlf & vbcrlf & txt

              ' Procedure to write output to a text file
              private sub writeTextFile(byval txt,byval strTextFilePath)
              Dim objFSO,objTextFile

               

              set objFSO = createobject("Scripting.FileSystemObject")

              set objTextFile = objFSO.CreateTextFile(strTextFilePath)

              objTextFile.Write(txt)

              objTextFile.Close
              SET objTextFile = nothing
              end sub

               

              Thanks,

              Surendar

              • 4. Re: How to execute a VBScript content through NSH script
                Bill Robinson

                when you say it's not working what do you mean?  is the vbs executing on the target ?  is the vbs not getting created on the target? etc...

                • 5. Re: How to execute a VBScript content through NSH script
                  Naren S

                  Hi Bill,

                   

                  Sorry for not being elloborative. Issue is that the vbs script file is not getting created on the target servers.

                   

                  Thanks,

                  Surendar

                  • 6. Re: How to execute a VBScript content through NSH script
                    Bill Robinson

                    Is it getting created on the appserver running the job in /tmp ?  (maybe comment out the rm commands at the end that do cleanup)

                     

                    Also, what’s the vbs script doing ?

                    • 7. Re: How to execute a VBScript content through NSH script
                      Jim Wilson

                      Hi Surendar,

                       

                      Any news for us?

                      If the responses have been correct or helpful, please mark them accordingly, ad let us know if this is resolved.

                       

                      Thanks & Regards,

                      Jim

                      • 8. Re: How to execute a VBScript content through NSH script
                        Naren S

                        Hi Bill/Jim,

                        Sorry, I was on a long vacation, and couldn't respond to your post.

                         

                        The file isn't getting created in the appserver as well.

                         

                        This VBScript is to report the free diskspace of the target systems.

                        • 9. Re: How to execute a VBScript content through NSH script
                          Bill Robinson

                          so put some break points in the script to ensure the vbs script is being created on the target, and take out the rm at the end.

                          • 10. Re: How to execute a VBScript content through NSH script


                            HI Bill,

                             

                            I'm trying to use your method to run a very simple vbscript (in my feeble attempts to get ANY vbscript working) via BMC). Here is my code

                             

                            #!/bin/nsh

                            FULL_PATH_THIS_FILE="$0"
                            THIS_FILE=`basename "${FULL_PATH_THIS_FILE}"`

                            # Find location of embedded script
                            LENGTH_OF_MAIN_SCRIPT=`cat "$FULL_PATH_THIS_FILE" | grep -n '### END OF MAIN SCRIPT ###' | grep -v grep | cut -d ':' -f1`

                            # Increment this by one to move past the line identifier
                            LENGTH_OF_MAIN_SCRIPT=`expr $LENGTH_OF_MAIN_SCRIPT + 1`

                            # Extract Script
                            tail +$LENGTH_OF_MAIN_SCRIPT "$FULL_PATH_THIS_FILE" > "/tmp/$$.vbs"

                            for target in ${@}
                            do
                            ## cp /tmp/$$ //${target}/tmp/$$.vbs
                            nexec -i -l ${target} cmd /c "cscript c:\\\tmp\\\$$.vbs"

                            ##rm -f //${target}/tmp/$$.vbs
                            done
                            ##rm -f /tmp/$$
                            exit 0

                            ### END OF MAIN SCRIPT ###

                            objofile = "c:\tmp\output.txt"

                            Set oFSO = CreateObject("Scripting.FileSystemObject")
                            Set objShell = WScript.CreateObject("WScript.Shell")

                            set ofile = oFSO.OpenTextFile(objofile,2,true)
                            ofile.close

                             

                             

                            I can see that the vbscript is created on the remote server but it does not seem to be run.

                            When I logon to the server and run the script manually (using cscript) it works a creates a txt file called output.txt in the c:\tmp folder.

                             

                            Any ideas; could it be anything to do with the way cscript is being called? (I have left out the /nolog option which I do not think is a valid switch for cscript) (OH! I also removed the cp command as it did not seem to be working; I simply added .vbs to the end of the tail command)

                             

                            Thanks

                            • 11. Re: How to execute a VBScript content through NSH script
                              Bill Robinson

                              if this is a type 1 nsh job/script you can change this like:

                              nexec -i -l ${target} cmd /c "cscript c:\\\tmp\\\$$.vbs"

                              to

                              nexec -i -l ${NSH_RUNCMD_HOST} cmd /c "cscript c:\\\tmp\\\$$.vbs"

                               

                              and see if it works.

                              • 12. Re: How to execute a VBScript content through NSH script

                                Hi

                                 

                                Just an update.

                                 

                                On the destination server (the server I run the NSH script against) I have opened up the rscd.log file.

                                 

                                I can see that the following commands are run

                                 

                                nsh

                                cat

                                cut

                                grep

                                tail

                                cp (I can see the cp commands were being run before I took out cp)

                                 

                                Obviously these are the commands in the script that I posted above.

                                The one command that is not mentioned in rscd.log is nexec

                                 

                                Thats the command that should run my vbscript....any ideas why nexec is not being run.
                                Should I find a file called nexec.exe on the target server?

                                Thanks

                                • 13. Re: How to execute a VBScript content through NSH script

                                  Bill,

                                   

                                  Apologies I completely missed your comment on 29th October.

                                   

                                  I have tried your suggestion and still no luck.

                                   

                                  The vbs file is created but its not being run. Should I see a reference to nexec in the rscd.log file?

                                  Thanks

                                  p.s. I'm not sure what a type 1 script is.  I simply create an NSH script.  Then I create a NSH Script job calling the NSH script.

                                  • 14. Re: How to execute a VBScript content through NSH script
                                    Bill Robinson

                                    type 1 is the 1st script type when you create a nsh script object:

                                     

                                    put an echo in front of the nexec:

                                    echo nexec -i -l ${NSH_RUNCMD_HOST} cmd /c "cscript c:\\\tmp\\\$$.vbs"

                                     

                                    and see what that shows.

                                    1 2 Previous Next