Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Unix Script  (Read 4108 times)

0 Members and 1 Guest are viewing this topic.

viceroy2528

    Topic Starter


    Newbie

    Unix Script
    « on: July 15, 2010, 11:20:55 AM »

    Would anyone by chance have a Unix Script that would parse the output of a command for the required data and then issue another command with this data?

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Unix Script
    « Reply #1 on: July 15, 2010, 04:09:48 PM »
    Take a look at
    Unix Script Examples
    http://UNIX.ittoolbox.com 

    ghostdog74



      Specialist

      Thanked: 27
      Re: Unix Script
      « Reply #2 on: July 15, 2010, 08:36:48 PM »
      Would anyone by chance have a Unix Script that would parse the output of a command for the required data and then issue another command with this data?
      what are you trying to parse? describe more clearly what you want to do.

      viceroy2528

        Topic Starter


        Newbie

        Re: Unix Script
        « Reply #3 on: July 16, 2010, 05:13:36 AM »
        Command
            tesmcmd jobmon +i -a 41844

        Return
              <execute>
           <cmd_name>jobmon</cmd_name>
           <result>
             <jobrun>
               <job_run_id>3318780</job_run_id>
             </jobrun>
           </result>

        I want to take the returned job_run_id and pass it to command

            tesmcmd jobrelease 3318780

        ghostdog74



          Specialist

          Thanked: 27
          Re: Unix Script
          « Reply #4 on: July 16, 2010, 06:19:54 AM »
          Code: [Select]
             linux$ var=$(tesmcmd jobmon +i -a 41844 | awk -vRS="</job_run_id>" '/job_run_id/{gsub(/.*job_run_id>/,"");print}')
             linux$ tesmcmd jobrelease $var

          KenJackson



            Beginner
          • Thanked: 1
            • Yes
            • Jackson I/O
          • Experience: Experienced
          • OS: Linux variant
          Re: Unix Script
          « Reply #5 on: July 17, 2010, 12:03:35 AM »
          Alternately,
          Code: [Select]
          var="$(tesmcmd jobmon +i -a 41844 | sed -n "/run_id/s/[^0-9]//gp")"
          tesmcmd jobrelease $var

          Some explanation:

          var="$( ... )" captures the output to a variable,
          -n tells sed to not output anything unless the p flag is given,
          /run_id/ selects only the line that has that text,
          s/...// is the substitution syntax, though we are substituting nothing thus deleting,
          [^0-9] matches any non-numeric character,
          g makes the substitution global on matching lines,
          p means print the results.