› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › set variable return from hcicomd
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
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”.
I tested the command in my previous post and it worked on my system.
#!/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
}
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:
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.
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 …
msiAttach
set msi [msiGetStatSample $thread_name]
keylget msi PSTATUS
Dennis
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:
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
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: