Write to file when user disconnects

Hello,
I have an IVR that plays a message and gathers information from clients who call in. We would like to be able to recognize when a caller hangs up instead of selecting the disconnect option. Is there a function in asterisk that can do this? I have not found one, so far… Below is the code that I have in my extentions.conf file so far:

[inbound]
; Answer the phone
exten => 1234567890,1,Answer

;Set Variables
exten => 1234567890,2,Set(OPTION="HANGUP")
exten => 1234567890,3,Set(CID=${CALLERID(num)})
exten => 1234567890,4,Set(SCODE="NULL")

exten => 1234567890,5,NoOp(${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)} ${CID} ${OPTION})
exten => 1234567890,6,Goto(10)

; Play main IVR message set response to CHOICE
exten => 1234567890,10,read(CHOICE,CLIENT_IVR_Main,1,)

; Check to see what result is and go to proper option
exten => 1234567890,20,Gotoif($[${CHOICE}=1]?30:21)
exten => 1234567890,21,Gotoif($[${CHOICE}=2]?40:10)

; If choice is 1 record caller ID and hangup
exten => 1234567890,30,Set(OPTION="Call-Back_Same-Number")
exten => 1234567890,31,NoOp(${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)} ${CID} ${OPTION})
exten => 1234567890,32,Goto(1313)

; If coice is 2 play message and gather new number
exten => 1234567890,40,Set(OPTION="Call-Back_New-Number")
exten => 1234567890,41,read(SCODE,CLIENT_IVR_Option2_withBeep,10,)
exten => 1234567890,42,GotoIf($[${LEN(${SCODE})}=10]?43:40)
exten => 1234567890,43,Playback(CLIENT_You_Entered)
exten => 1234567890,44,SayDigits(${SCODE})
exten => 1234567890,45,read(SCHOICE,CLIENT_Correct_Press_One,1,)
exten => 1234567890,46,Gotoif($[ ${SCHOICE} = 1 ]?1313:40)
exten => 1234567890,47,NoOp(${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)} ${CID} ${SCODE} ${OPTION})

;Hangup
exten => 1234567890,1313,TrySystem(/bin/echo ${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}, ${CID}, ${SCODE}, ${OPTION} >> /opt/codes.log)
exten => 1234567890,1314,Playback(CLIENT_Thank_You)
exten => 1234567890,1315,Hangup()


;Record data if user hangs up.
exten => 1234567890,n,ID_USER_HANGSUP(/bin/echo ${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}, ${CID}, ${SCODE}, ${OPTION} >> /opt/codes.log)

h extension.

Okay, thanks… I’ll see if I can find something on that, and how to use it…

Thanks! I was trying to make it a LOT harder than it needed to be… In case anyone else needs help, below is what I changed (only the last line)…

[inbound]
; Answer the phone
exten => 1234567890,1,Answer

;Set Variables
exten => 1234567890,2,Set(OPTION="HANGUP")
exten => 1234567890,3,Set(CID=${CALLERID(num)})
exten => 1234567890,4,Set(SCODE="NULL")

exten => 1234567890,5,NoOp(${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)} ${CID} ${OPTION})
exten => 1234567890,6,Goto(10)

; Play main IVR message set response to CHOICE
exten => 1234567890,10,read(CHOICE,CLIENT_IVR_Main,1,)

; Check to see what result is and go to proper option
exten => 1234567890,20,Gotoif($[${CHOICE}=1]?30:21)
exten => 1234567890,21,Gotoif($[${CHOICE}=2]?40:10)

; If choice is 1 record caller ID and hangup
exten => 1234567890,30,Set(OPTION="Call-Back_Same-Number")
exten => 1234567890,31,NoOp(${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)} ${CID} ${OPTION})
exten => 1234567890,32,Goto(1313)

; If coice is 2 play message and gather new number
exten => 1234567890,40,Set(OPTION="Call-Back_New-Number")
exten => 1234567890,41,read(SCODE,CLIENT_IVR_Option2_withBeep,10,)
exten => 1234567890,42,GotoIf($[${LEN(${SCODE})}=10]?43:40)
exten => 1234567890,43,Playback(CLIENT_You_Entered)
exten => 1234567890,44,SayDigits(${SCODE})
exten => 1234567890,45,read(SCHOICE,CLIENT_Correct_Press_One,1,)
exten => 1234567890,46,Gotoif($[ ${SCHOICE} = 1 ]?1313:40)
exten => 1234567890,47,NoOp(${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)} ${CID} ${SCODE} ${OPTION})

;Hangup
exten => 1234567890,1313,TrySystem(/bin/echo ${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}, ${CID}, ${SCODE}, ${OPTION} >> /opt/codes.log)
exten => 1234567890,1314,Playback(CLIENT_Thank_You)
exten => 1234567890,1315,Hangup()


;Record data if user hangs up.
exten => h,1,TrySystem(/bin/echo ${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}, ${CID}, ${SCODE}, ${OPTION} >> /opt/codes.log)