Lois_Answer_Code=`sipsak -vv -s sip:192.168.1.3|grep -A 1 "reply received after"|grep SIP|awk '{print $2}'`
How to find the exit status of
|
Lois_Answer_Code=`sipsak -vv -s sip:192.168.1.3|grep -A 1 "reply received after"|grep SIP|awk '{print $2}'`
How to find the exit status of
|
The exit status of any command can be extracted using "$?"
For eg:-
sipsak -vv -s sip:192.168.1.3
echo $?
--ahamed
First i will run the below:
Then i need to find the exit status of the below portion of the above command:
sipsak -vv -s sip:192.168.1.3 && es=$? || es=$? | awk '/reply received after/ {getline; $0~/SIP/ {print $2}}'
echo $es
Not working. I need to save the output of the command in the variable Lois_Answer_Code as well
what not working ?
post the error or what you are getting ?
can you post the output of the below command
sipsak -vv -s sip:192.168.1.3
And let us know, what string you want to extract
Want to extract 200 after the "reply received" line"
Lois_Answer_Code=$(sipsak -vv -s sip:192.168.1.3 | awk '/reply received after/ {getline; if($0~/SIP/){print $2}}')
And what about the exit status?
What shell are you using?
Newer Korn, and Bash, shells have pipefail:
$ ls blah 2>&1 | grep .
ls: blah: No such file or directory
$ echo $?
0
$ set -o pipefail
$ ls blah 2>&1 | grep .
ls: blah: No such file or directory
$ echo $?
2
$ echo ${PIPESTATUS[@]} # BASH - show the exit status of all commands in the pipeline
2 0
You could run it in a subshell and store the exit status in a file until it's needed.
Lois_Answer_Code=$((sipsak -vv -s sip:192.168.1.3; echo $? > status) | grep ... )
sipssak_exit_status=$(cat status)
Regards,
Alister