Question
· Mar 18, 2016

How to return the status code of Cache process to OS shell script?

Straight-forward way to do it is well known and looks like this: 
------------------------------------------------------------ sample #1 --------

echo "Try to freeze Cache instance $instance"
rm -f $mydir/db_temp
csession $instance -U%SYS << EOF >/dev/null
zn "%SYS"
set rc=##Class(Backup.General).ExternalFreeze()
set fn="$mydir/db_temp"
o fn:("WNS"):1 if \$t u fn w rc c fn
h
EOF
read rc < db_temp
if [ "$rc" = "1" ]
then
 echo "...OK, system is frozen."
else
 echo "** Copy ABORTED: freeze rc = $rc"
 exit
fi

-----------------------------------------------------------------------------------

Documentation states that the same can be written in much more short and readable style (and it really works):

------------------------------------------------------------ sample #2 --------

echo "Try to freeze Cache instance $instance"
csession $instance -U%SYS "##Class(Backup.General).ExternalFreeze()"
rc=$?
if [ $rc -eq 5 ]
then
 echo "...OK, system is frozen."
else
 echo "** Copy ABORTED: freeze rc = $rc"
 exit
fi

----------------------------------------------------------------------------------

Backup.General class lacks of source for some reason, so I tried to reconstruct it methods' behavior:

---

Class User.InstARMTune Extends %RegisteredObject
{
  ClassMethod ret(= 1) As %Integer
  {  return n  ; or quit n }

}
---

calling it in the same manner:

csession cache -U%SYS "##class(User.InstARMTune).ret(2)"
rc=$?

with no success: it allways returns 0. What I am doing wrong?
 

Discussion (4)1
Log in or sign up to continue