Observium integration with Request Tracker

My RT version is 4.4.1 with apache2 , mod_perl2 and mysql
We run an observium server and I am trying to integrate it with our RT ticketing so a new alert creates a ticket , and an alert Recover updates the same ticket and closes.
For this I written a bash script which is called from an observium action , the bash script uses the rt command line and works as expected , HOWEVER the script is not existing because the rt command is not closing and over time , I see few instances of the script running which eventually cause out of memory problem

Have anyone come across this kind of problem , I would guess its not specific to Observium , but a general RT cli issue ?? I can post the whole bash script if needed but in summary the RT related lines:

!#open Ticket or see it ticket exists
g=$(grep $grepstring /opt/observium/checks/RaTickets |awk -F “,” ‘{print $4}’)
if [[ $g =~ ^[0-9]+$ ]]; then
ncmd=$(/opt/observium/checks/rt comment ticket/$g -m “$commentstring” )
if [[ $alertstatus == “RECOVER” ]]
ncmdstatus=$(/opt/observium/checks/rt edit ticket/$g set status=‘resolved’ )
ncmd=$(/opt/observium/checks/rt create -t ticket set subject=”$subject" queue=“Monitoring” Text="$createstring" | awk ‘{print $3}’ )
ncmdcf=$(/home/raed.elhames/rt edit $ncmd set CF-Hostname="$devicehostname" CF-FaultyEntity="$entitytype" CF-EntityName="$entityname" CF-AlertType="$alertmessage" CF-Alert_Id="$alertid" )
echo $timestamp,$alertid,$alertstatus,$ncmd >> /opt/observium/checks/RaTickets
logrtout=$(/opt/observium/checks/rt logout)
echo $ourenv >> /opt/observium/checks/ObsEnv

Any help will be appreciated.