Is it possible to execute lines in a script when the caller disconnects?
I.e. to check when the last person leaves a conference room so you know it is safe to move the recording file.
Your question is a little bit vague, and a few details like what version of Asterisk and what language you are fluent in would help.
If you are asking if you can execute an AGI in the ‘h’ extension, yes.
If you are asking if you can continue executing an AGI when a caller hangs up, yes. Asterisk will deliver a SIGHUP. If you have established a signal handler (man sigaction or man signal) to ‘catch’ or ‘trap’ the signal, you can do as you please.
When a person hangs up their phone, Asterisk jumps to the “h” extension in the current context. From there, you can do any of the normal dialplan stuff that doesn’t require a call to be bridged; including AGI scripts and shell commands using System().