login | register
Sat 05 of Jul, 2008 [19:17 UTC]

voip-info.org

Search with Google
Search this site with Google. Results may not include recent changes.
 
Google Ads
Shoutbox
  • Samuel, Thu 03 of Jul, 2008 [13:41 UTC]: ok thank you
  • Mats Karlsson, Thu 03 of Jul, 2008 [13:37 UTC]: Nice Samuel, will look forward to rad it.
  • bwl_fernstudent, Thu 03 of Jul, 2008 [09:08 UTC]: Your blog shows some usefull code
  • Samuel, Thu 03 of Jul, 2008 [08:04 UTC]: I'll translate it, for sure
  • Mats Karlsson, Wed 02 of Jul, 2008 [20:46 UTC]: LOL, in french! Translate it to English and I will read it.
  • Samuel, Wed 02 of Jul, 2008 [08:07 UTC]: Hello, i wrote a blog about Asterisk, speaking about installation,programming and more http://sambranche.blogspot.com/
  • Nick Barnes, Tue 01 of Jul, 2008 [17:46 UTC]: Steve - Asterisk doesn't 'fit into linux' - it's an application which runs on top of Linux.
  • Steve, Mon 30 of Jun, 2008 [18:07 UTC]: anyone know where I can find a block diagram of how asterisk fits into linux. my f'ing bosses want me to draw something up.. ugh.
  • akbar, Fri 27 of Jun, 2008 [10:37 UTC]: marley_boyz@yahoo.com how to configure call forward, call back, call pick up using TDM and asterisk 1.2.13... please help me.. thx...
  • Matthew Williams, Tue 24 of Jun, 2008 [22:37 UTC]: We are looking for Tier II VoIP Support Technicians in St Louis. Send resumes to mwilliams AT voxitas DOT com.
Server Stats
  • Execution time: 0.49s
  • Memory usage: 2.61MB
  • Database queries: 35
  • GZIP: Disabled
  • Server load: 0.61

Asterisk cmd System

System()

For Asterisk >=1.2

Synopsis

 Execute a system (Linux shell) command

Description

 System(command) - System command alone
 System(command arg1 arg2 etc) - Pass in some arguments
 System(command|args) - Use the standard asterisk syntax to pass in arguments

Technical Info

Executes a command by using system().
System() passes the string unaltered to system(3). Running "man 3 system" will show exactly what system(3) does:

  system()  executes  a command specified in string by calling
  /bin/sh -c string, and returns after the command has been completed.

Therefore System(command arg1 arg2 etc) can be used to pass along arguments.

Return codes

 System(command): Executes a command  by  using  system(). If the command fails, the console should report a fallthrough.
 Result of execution is returned in the SYSTEMSTATUS channel variable:
 FAILURE      Could not execute the specified command
 SUCCESS      Specified command successfully executed
NOTE - not documented, but can also return APPERROR

As far as I can understand it will return APPERROR when the command exits with a non-zero return-value.

Old behaviour:
If the command itself executes but is in error, and if there exists a priority n + 101, where 'n' is the priority of the current instance, then the channel will be setup to continue at that priority level. Note that this jump functionality has been deprecated and will only occur if the global priority jumping option is enabled in extensions.conf (priorityjumping=yes).


app_backticks (3rd party addition)

Execute a shell command and save the result as a variable; available as both application and function from here. A patch to use this application with the new module system in Asterisk 1.4+ can be found here

Example 1

 exten => s,1,system(echo "${DATETIME} - ${CALLERID} - ${CHANNEL}" >> /var/log/asterisk/calls)

Example 2

 ; dial 700 = Restart Asterisk
 exten => 700,1,Playback(posix-restarting) ; "Restarting asterisk"
 exten => 700,2,Wait(1)
 exten => 700,3,System(/usr/sbin/asterisk -rx reload)
 exten => 700,4,Hangup

Example 3

; Extension 200 Mini Call ID WinPopup Example
exten => 200,1,NoOp(${CALLERID} ${DATETIME})
exten => 200,2,System(/bin/echo -e "'Incoming Call From: ${CALLERID} \\r Received: ${DATETIME}'"|/usr/bin/smbclient -M target_netbiosname)
exten => 200,3,Dial,sip/sipuser|30|t        
exten => 200,4,Congestion

Example 4

; Dump call info to a serial receipt printer on ttyS1
exten => 200,1,NoOp(${CALLERID} ${DATETIME})
exten => 200,2,System(/bin/echo "'${CALLERID} ${DATETIME}'" > /dev/ttyS1)
exten => 200,3,Dial,sip/sipuser|30|t        
exten => 200,4,Congestion

Security


My associate received a call from PG&E and realized the horror of System()

Problem

Running System() has access to any program the user running asterisk has access to
CALLERID can be set by a remote user

Example

exten => 200,1,Set(CALLERID(NAME)=PG&/bin/echo BADIDEA > /ROOTED.txt)
exten => 200,2,System(/bin/echo -e "'Incoming Call From: ${CALLERID} \\r Received: ${DATETIME}'"|/usr/bin/smbclient -M target_netbiosname)

Measure 1

By using perl I was able to prevent the first example but I'm sure the possibility is still there:

exten => 200,1,Set(CALLERID(NAME)=PG&/bin/echo BADIDEA > /ROOTED.txt)
exten => 200,2,System(/bin/perl -e 'print Incoming Call From:" . "${CALLERIDNAME}" | /usr/bin/smbclient -M target_netbiosname)

Measure 2


Fine tune this to your liking:

[macro-smb-cid]
exten => s,1,NoOp
exten => s,2,Set(regx="([a-zA-Z0-9]+)")
exten => s,3,Set(CCIDNAME=$["${CALLERIDNAME}": ${regx}])
exten => s,4,Set(regx="([0-9]+)")
exten => s,5,Set(CCIDNUM=$["${CALLERIDNUM}": ${regx}])
exten => s,6,TrySystem(/usr/bin/perl -e \'print "${DATETIME} " . " ${CCIDNAME} " . " \<${CCIDNUM}\>" \' | /usr/bin/smbclient -M target_netbiosname)

Update!! Asterisk-1.4 returns 0 (as it should) when your regex matches. Instead use the function FILTER.
This example is experimental...
[macro-smb-cid]
exten => s,1,NoOp
exten => s,2,Set(FLTNA=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz)
exten => s,3,Set(CIDNA=${FILTER(${FLTNA},${CALLERID(NAME)})})
exten => s,4,Set(FLTNU=(0123456789)
exten => s,5,Set(CIDNU=${FILTER(${FLTNU},${CALLERID(num)})})
exten => s,6,TrySystem(/usr/bin/perl -e \'print "${DATETIME} " . " ${CCIDNAME} " . " \<${CCIDNUM}\>" \' | /usr/bin/smbclient -M target_netbiosname)

I'd like to hear from you if you know another way... cwidger@gmail.com


See also



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

Created by oej, Last modification by Dan on Wed 07 of May, 2008 [19:41 UTC]

Comments Filter

Re: System() after hangup

by Asbjørn Z. Kjær on Saturday 13 of January, 2007 [21:30:48 UTC]
I believe you can use the special h extension to run commands after a hangup. The problem is that during a Dial, the dialplan only continues to execute in the same context, if the called party hangs up first, otherwise, the Dial will terminate the call immediately (or is it when the calling party hangs up first, cant remember :)). The h extension will handle this though. More info on the Asterisk h extension

On a more general note, the APPERROR value of SYSTEMSTATUS is returned by the TrySystem command, when the requested program is executed ok, but has a non-zero return code, according to core show function TrySystem in Asterisk 1.4

System() after hangup

by Brandon Blackmoor on Friday 01 of December, 2006 [16:07:08 UTC]
I need to run a System command after a call has ended and the CDR record has been written. I have tried everything I can think of, using Dial "g", System, Macro, Goto, GotoIf, etc., and either the System() command executes before the CDR record is written, or it does not execute at all. At it's simplest, this is what I would like to have happen:

exten => s,n,Dial(Zap/g1/${ARG1}|120|g)
exten => s,n,System(/usr/scripts/asterisk_etl.php ${UNIQUEID})

Any help would be greatly appreciated.
Edit

What?!

by Anonymous on Thursday 10 of February, 2005 [06:07:53 UTC]
Is it coming back???
Edit

Command has disappeared

by Anonymous on Monday 31 of January, 2005 [19:30:29 UTC]
It appears that the System command no longer works ( CVS-HEAD-01/31/05-19:10:33 ) Instead now an error " pbx_extension_helper: No application " is shown

Please update this page with new information, just login and click on the "Edit" or "Add Comment" button above. Get a free login here: Register Thanks! - support@voip-info.org

Page Changes | Comments

Sponsored by:

Terms of Service Privacy Policy
© 2003-2008 VOIP-Info.org LLC

Powered by bitweaver