Bash AGI . Works fine but ERROR in console

Hello.

Just playing with a simple Bash AGI script (everything is already done with Python, now Bash is for fun :slight_smile:

So, the script takes ${CALLERID(num)} as an argument , and if it’s in the list, sends HANGUP to Asterisk.
Everything works fine, but an ERROR appears in the console:

[2015-02-07 14:55:20]     -- Executing [7384230NNNN@incoming-reg42:1] AGI("SIP/7384230NNNN-000fc9a5", "blackbash.agi,7922573iiii") in new stack
[2015-02-07 14:55:20]     -- Launched AGI Script /var/spool/asterisk_2/apps/AGI/blackbash.agi
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_request: blackbash.agi
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_channel: SIP/7384230NNNN-000fc9a5
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_language: ru
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_type: SIP
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_uniqueid: pbx-gw-1423320920.1034677
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_version: 1.6.2.19
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_callerid: 7922573iiii
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_calleridname: unknown
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_callingpres: 0
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_callingani2: 0
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_callington: 0
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_callingtns: 0
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_dnid: 7384230NNNN
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_rdnis: unknown
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_context: incoming-reg42
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_extension: 7384230NNNN
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_priority: 1
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_enhanced: 0.0
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_accountcode: 
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_threadid: 34535455488
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> agi_arg_1: 7922573iiii
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> 
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Rx << HANGUP
[2015-02-07 14:55:20] <SIP/7384230NNNN-000fc9a5>AGI Tx >> 200 result=1
[2015-02-07 14:55:20] ERROR[48132]: utils.c:1130 ast_carefulwrite: write() returned error: Broken pipe
[2015-02-07 14:55:20]     -- <SIP/7384230NNNN-000fc9a5>AGI Script blackbash.agi completed, returning 4
[2015-02-07 14:55:20]   == Spawn extension (incoming-reg42, 7384230NNNN, 1) exited non-zero on 'SIP/7384230NNNN-000fc9a5'

The script itself:

#!/usr/local/bin/bash

file="/usr/local/etc/asterisk_2/blackbashnums.txt"
firstarg=$1

if grep -q ${firstarg: -10} "$file"
then echo 'HANGUP'
else echo 'NOOP'
fi

The blackbashnums.txt is a simple text file with 11-digits numbers, one per line (first digit is a country code, as you see, we cut it off in the script).

PS: haven’t tried ‘asterisk -vvvvcg’ yet, calls are all day long. Maybe only at night…