set variable return from hcicomd

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf set variable return from hcicomd

  • Creator
    Topic
  • #49187
    Hongle Sun
    Participant

      In tcl script can i do following:

      set proto_status [exec hcimsiutil -dd $thread_name |grep “^Proto Status” | awk -F: ‘{print $2}’| tr -d ‘ ‘]

      if not, how can i do that?

      Thanks

    Viewing 8 reply threads
    • Author
      Replies
      • #61031
        David Barr
        Participant

          How about this?

          Code:

          set proto_status [exec sh -c “hcimsiutil -dd $thread_name | awk ‘/^Proto Status/ {print $NF}'”]

          The “pipe” character is normally interpreted by the shell, and if you use “exec”, there is no shell to interpret the “pipe”.  That’s why you have to add “sh -c”.

        • #61032
          Hongle Sun
          Participant

            sorry, it doesnot work in that way, any ideal?

          • #61033
            David Barr
            Participant

              You’re not giving us much to work with.  Why don’t you post the entire script that you are trying to get working, a description of how you are trying to run it, and a copy of the output of the script including error messages?  Also, what version of Cloverleaf are you running and what operating system are you using?

              I tested the command in my previous post and it worked on my system.

            • #61034
              Hongle Sun
              Participant

                Thanks David, we are using quovadx 54. on AIX 5.3. See the script

                #!/usr/bin/ksh

                # this line to escape the next line from the tcl interpreter

                exec hcitcl “$0” “$@”

                set thread_name [lindex $argv 0]

                set process_name [lindex $argv 1]

                if {[file exists “/quovadx/qdx5.4/integrator/hnatest/exec/processes/$process_name/pid”] != 1} {

                     exec hcienginerun -p $process_name

                     sleep 10

                   }

                   exec hcicmd -p $process_name -c “$thread_name pstop”

                   exec sleep 10

                   exec hcicmd -p $process_name -c “$thread_name pstart”

                   exec sleep 20

                 

                 

                   set proto_status [exec ksh -c hcimsiutil -dd $thread_name | grep “^Proto Status” | awk -F: ‘{print $2}’ | tr -d ‘ ‘]

                 

                if { [$proto_status != “3” ] } {

                     exec hcienginestop -p $process_name

                   }

              • #61035
                David Barr
                Participant

                  This is wrong:

                  Code:

                  set proto_status [exec ksh -c hcimsiutil -dd $thread_name | grep “^Proto Status” | awk -F: ‘{print $2}’ | tr -d ‘ ‘]

                  You added the “ksh -c”, but “ksh -c” expects only one argument for the command.  You’ll have to put the command in quotes.

                  Maybe you should try:

                  Code:

                  set proto_status [exec ksh -c “hcimsiutil -dd $thread_name | grep ‘^Proto Status’ | awk -F: ‘{print $2}’ | tr -d ‘ ‘”]

                  If that doesn’t work, post a copy of the error messages.

                  Alternatively, you could try using the exact command that I gave you in my first response.

                • #61036
                  Hongle Sun
                  Participant

                    Sorry, I actually copied and past the post in my code, neither of them can do for me.. and i try to get you the error, and not sure where to find them. please help

                  • #61037
                    Dennis Pfeifer
                    Participant

                      ok .. I’ll give it a try …

                      Code:

                      set proto_status [string trim [lindex [split [lindex [split [exec ksh -c “hcimsiutil -dd $thread_name”] “n”] 11] :] 1]]

                      whew…

                      of course there’s always …

                      Code:


                      msiAttach

                      set msi [msiGetStatSample $thread_name]
                      keylget msi PSTATUS

                      Dennis

                    • #61038
                      Russ Ross
                      Participant

                        You can use the “exec” or “system” command in TCL to run command line stuff like you are trying to do.

                        Of course you will have to get the syntax correct as you have already discovered.

                        It appears to me you are trying to duplicate in TCL what I did in one of my KSH scripts, which I wrote long before I knew much about TCL.

                        However, to do something like you want in TCL would be better served with logic like the one found in our TCL proc oth_get_stats.

                        Even though I’m using this proc, it may only be useful to you as an example of how to get your hands on hcimsiutil info in a TCL proc.

                        Note it is exteremely important to check for the monitorShmemFile before doing msiAttach or you will generate alot of shared memory issues and wonder what is causing them.

                        In other words, this line of code is essential for safety:

                        if { [lsearch -exact [ls $HciSiteDir/exec] monitorShmemFile] == -1 } { return }

                        Code:

                        proc oth_get_stats {THREAD} {

                            global HciSiteDir
                            if { [lsearch -exact [ls $HciSiteDir/exec] monitorShmemFile] == -1 } { return }

                            msiAttach

                            set pStatus “unknown”
                            set obDataQD “0”
                            set pLastRead “0”
                            set msgsIn “0”
                            set pLastWrite “0”
                            set msgsOut “0”

                            set bytesIn “0”
                            set bytesOut “0”
                            set ibLatency “0”
                            set obLatency “0”
                            set totLatency “0”

                            set tocEntry [msiTocEntry $THREAD]
                            keylget tocEntry INDEX threadIndex
                            msiGetStatSample $threadIndex stats
                            keylget stats PSTATUS pStatus
                            keylget stats OBDATAQD obDataQD
                            keylget stats PLASTREAD pLastRead
                            keylget stats MSGSIN msgsIn
                            keylget stats PLASTWRITE pLastWrite
                            keylget stats MSGSOUT msgsOut
                            keylget stats BYTESIN bytesIn
                            keylget stats BYTESOUT bytesOut
                            keylget stats IBLATENCY ibLatency
                            keylget stats OBLATENCY obLatency
                            keylget stats TOTLATENCY totLatency

                            if {$pLastRead == 0} {
                                set pLastRead “never”
                            } else {
                                set pLastRead [clock format $pLastRead -format “%a %b %d %H:%M:%S”]
                            }

                            if {$pLastWrite == 0} {
                                set pLastWrite “never”
                            } else {
                                set pLastWrite [clock format $pLastWrite -format “%a %b %d %H:%M:%S”]
                            }

                            set outStats “$pStatus^$obDataQD^$pLastRead^$msgsIn^$pLastWrite^$msgsOut^$bytesIn^$bytesOut^$ibLatency^$obLatency^$totLatency”
                            return $outStats
                        }

                        Russ Ross
                        RussRoss318@gmail.com

                      • #61039
                        Hongle Sun
                        Participant

                          Thank you all so much. I just found one may cause the problem. if i run

                          exec hcimsiutil -dd $thread_name | grep “^OB Data QD” | awk -F: ‘{print $2}’ | tr -d ‘ ‘] from shell window, and the result returned to the window are:

                          Author
                          Replies
                        Viewing 8 reply threads
                        • The forum ‘Cloverleaf’ is closed to new topics and replies.