Unix: Grabbing dates from file and sorting them - unix

I have multiple files that look like this:
//file start
$thing1 = {'item1' => '0', 'item2 => '3', 'itemDate' => '2013-10-01'};
$thing2 = {'item1' => '0', 'item2 => '3', 'itemDate' => '2012-11-01'};
$thing3 = {'item1' => '0', 'item2 => '3', 'itemDate' => '2014-12-01'};
//file end
Using Unix, what is the best way to grab all of the items in a file that are dates. I know that the items I'm looking for in the file look like
{somethingDate = '1111-11-11'}
From this I want to grab '1111-11'11'. File one will have multiple 'fileOneDate' entries and file two will have multiple 'fileTwoDate' entries, etc. My goal is to take all of these dates that are '*Date', remove duplicates, and sort them into an output file, which is easy enough using the sort command and pipes. However, I'm stuck on this first part. What I have so far looks like this:
<command I'm working on now that grabs dates> | sort -n > outputfile.txt
I believe the way to go would be an AWK script. What would be the right way to parse these files?

Do you need like this?
sed -n "s/.*'\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\)'.*/\1/p"
If you have -r option in sed,
sed -nr "s/.*'([0-9]{4}-[0-9]{2}-[0-9]{2})'.*/\1/p"
Test:
sat:~# echo "{somethingDate = '1111-11-11'}" | sed -n "s/.*'\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\)'.*/\1/p"
1111-11-11
sat:~#
sat:~# echo "$thing1 = {'item1' => '0', 'item2 => '3', 'itemDate' => '2013-10-01'};" | sed -n "s/.*'\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\)'.*/\1/p"
2013-10-01

grep -o is the simplest way to extract text.
sort -u to sort (duh) and remove duplicates.
grep -oE '\<[0-9]{4}-[0-9]{2}-[0-9]{2}\>' <<'END' | sort -u
$thing1 = {'item1' => '0', 'item2 => '3', 'itemDate' => '2013-10-01'};
$thing2 = {'item1' => '0', 'item2 => '3', 'itemDate' => '2012-11-01'};
$thing3 = {'item1' => '0', 'item2 => '3', 'itemDate' => '2014-12-01'};
$thing2b= {'item1' => '0', 'item2 => '3', 'itemDate' => '2012-11-01'};
$thing2c= {'item1' => '0', 'item2 => '3', 'itemDate' => 'foo2012-01-01bar'};
END
2012-11-01
2013-10-01
2014-12-01

If your sample file is called datefile, then:
$ sed -nr "s/.*Date' => '([^']+)'.*/\1/p" datefile | sort -n
2012-11-01
2013-10-01
2014-12-01
The above regex looks for lines containing Date' => 'datestring' and prints the datestring.
In more detail, the sed command consists of a substitution which, in sed-style, are written as s/old/new/options. The old part is a bit complicated so I will go through it piece by piece: the old regex looks for (a) .* means anything (any number of any characters), followed by (b) Date' => ', followed by (c) ([^']+) which means one or more characters that are not single quotes, followed by (d) a single quote, followed by (e) .*, again meaning anything. If a match is made, then that line is replaced with the date string (saved as \1 because the date string regex was in parens) and then, because of the p at the end of the expression, that date is printed. Because the -n option is given to sed, lines with no matching datestring are not printed.
If your sed does not support -r (OSX), then use a similar expression but with a few added backslashes:
sed -n "s/.*Date' => '\([^']\+\)'.*/\1/p" datefile | sort -n

Related

Typing pipe character prepends with backslash

I'm getting a weird and very annoying behavior in my terminal. When I type a protocol (i.e 'http:') then the pipe (|) character a backslash() is automatically inserted before the pipe character.
My test:
type 'htt'+'|' => 'ht|'
type 'htt:'+'|' => 'htt:|'
type 'http'+'|' => 'http|'
type 'http:'+'|' => 'http:\|'
type 'http://foo.com'+'|' => 'http://foo.com\|'
type 'curl http://foo.com'+'|' => 'curl http://foo.com\|'
type 'curl https://foo.com'+'|' => 'curl http://foo.com\|'
The same thing happens when I use 'ftp:' but not when I use 'telnet:'
Does anybody know what could be doing this?
This is my system:
OSX sierra
iTerm2 3.0.12
zsh 5.2 (x86_64-apple-darwin16.1.0)
pretzo (https://github.com/sorin-ionescu/prezto)

Dial plan not working in asterisk server

I am writing asterisk dial plan for testing purpose. I write this in my extension.conf:-
[demo]
exten => s,1,Answer
exten => s,n,Read(user_number)
exten => s,n,SayDigits(${user_number})
exten => s,n,System(echo 'User entered ${user_number}' >> /tmp/key.txt)
When i call on 8500, call successfully established, But when user press 1 or 2 or 3 key on sjphone then playback is not working. I can't hear any sound.
Here is my complete extension.conf:-
;
; Static extension configuration file, used by
; the pbx_config module. This is where you configure all your
; inbound and outbound calls in Asterisk.
;
; This configuration file is reloaded
; - With the "extensions reload" command in the CLI
; - With the "reload" command (that reloads everything) in the CLI
;
; The "General" category is for certain variables.
;
[general]
;
; If static is set to no, or omitted, then the pbx_config will rewrite
; this file when extensions are modified. Remember that all comments
; made in the file will be lost when that happens.
;
; XXX Not yet implemented XXX
;
static=yes
;
; if static=yes and writeprotect=no, you can save dialplan by
; CLI command 'save dialplan' too
;
writeprotect=yes
;
; If autofallthrough is set, then if an extension runs out of
; things to do, it will terminate the call with BUSY, CONGESTION
; or HANGUP depending on Asterisk's best guess (strongly recommended).
;
; If autofallthrough is not set, then if an extension runs out of
; things to do, asterisk will wait for a new extension to be dialed
; (this is the original behavior of Asterisk 1.0 and earlier).
;
autofallthrough=yes
;
; If clearglobalvars is set, global variables will be cleared
; and reparsed on an extensions reload, or Asterisk reload.
;
; If clearglobalvars is not set, then global variables will persist
; through reloads, and even if deleted from the extensions.conf or
; one of its included files, will remain set to the previous value.
;
clearglobalvars=no
;
; If priorityjumping is set to 'yes', then applications that support
; 'jumping' to a different priority based on the result of their operations
; will do so (this is backwards compatible behavior with pre-1.2 releases
; of Asterisk). Individual applications can also be requested to do this
; by passing a 'j' option in their arguments.
;
priorityjumping=yes
;
; You can include other config files, use the #include command
; (without the ';'). Note that this is different from the "include" command
; that includes contexts within other contexts. The #include command works
; in all asterisk configuration files.
;#include "filename.conf"
; The "Globals" category contains global variables that can be referenced
; in the dialplan with ${VARIABLE} or ${ENV(VARIABLE)} for Environmental
; variables,
; ${${VARIABLE}} or ${text${VARIABLE}} or any hybrid
;
;[globals]
#include "exten_gvars.inc"
;
; Sample entries for extensions.conf
;
;
[dundi-e164-canonical]
;
; List canonical entries here
;
;exten => 12564286000,1,Macro(std-exten,6000,IAX2/foo)
;exten => _125642860XX,1,Dial(IAX2/otherbox/${EXTEN:7})
[dundi-e164-customers]
;
; If you are an ITSP or Reseller, list your customers here.
;
;exten => _12564286000,1,Dial(SIP/customer1)
;exten => _12564286001,1,Dial(IAX2/customer2)
[dundi-e164-via-pstn]
;
; If you are freely delivering calls to the PSTN, list them here
;
;exten => _1256428XXXX,1,Dial(Zap/g2/${EXTEN:7}) ; Expose all of 256-428
;exten => _1256325XXXX,1,Dial(Zap/g2/${EXTEN:7}) ; Ditto for 256-325
[dundi-e164-local]
;
; Context to put your dundi IAX2 or SIP user in for
; full access
;
include => dundi-e164-canonical
include => dundi-e164-customers
include => dundi-e164-via-pstn
[dundi-e164-switch]
;
; Just a wrapper for the switch
;
switch => DUNDi/e164
[dundi-e164-lookup]
;
; Locally to lookup, try looking for a local E.164 solution
; then try DUNDi if we don't have one.
;
include => dundi-e164-local
include => dundi-e164-switch
;
; DUNDi can also be implemented as a Macro instead of using
; the Local channel driver.
;
[macro-dundi-e164]
;
; ARG1 is the extension to Dial
;
exten => s,1,Goto(${ARG1},1)
include => dundi-e164-lookup
;
; Here are the entries you need to participate in the IAXTEL
; call routing system. Most IAXTEL numbers begin with 1-700, but
; there are exceptions. For more information, and to sign
; up, please go to www.gnophone.com or www.iaxtel.com
;
[iaxtel700]
exten => _91700XXXXXXX,1,Dial(IAX2/${IAXINFO}#iaxtel.com/${EXTEN:1}#iaxtel)
;
; The SWITCH statement permits a server to share the dialplan with
; another server. Use with care: Reciprocal switch statements are not
; allowed (e.g. both A -> B and B -> A), and the switched server needs
; to be on-line or else dialing can be severly delayed.
;
[iaxprovider]
;switch => IAX2/user:[key]#myserver/mycontext
[trunk]
exten => _01,1,Dial(${trunk1})
exten => _01,2,Congestion
exten => _01.,1,Dial(${trunk1}/${EXTEN:2})
exten => _01.,2,Congestion
exten => _02.,1,Dial(${trunk2}/${EXTEN:2})
exten => _02.,2,Congestion
[trunkint]
;
; International long distance through trunk
;
exten => _9011.,1,Macro(dundi-e164,${EXTEN:4})
exten => _9011.,n,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
[trunkld]
;
; Long distance context accessed through trunk
;
exten => _91NXXNXXXXXX,1,Macro(dundi-e164,${EXTEN:1})
exten => _91NXXNXXXXXX,n,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
[trunklocal]
;
; Local seven-digit dialing accessed through trunk interface
;
exten => _9NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
[trunktollfree]
;
; Long distance context accessed through trunk interface
;
exten => _91800NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
exten => _91888NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
exten => _91877NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
exten => _91866NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
[international]
;
; Master context for international long distance
;
ignorepat => 9
include => longdistance
include => trunkint
[longdistance]
;
; Master context for long distance
;
ignorepat => 9
include => local
include => trunkld
[local]
;
; Master context for local, toll-free, and iaxtel calls only
;
ignorepat => 9
include => default
include => parkedcalls
include => trunklocal
include => iaxtel700
include => trunktollfree
include => iaxprovider
;
; You can use an alternative switch type as well, to resolve
; extensions that are not known here, for example with remote
; IAX switching you transparently get access to the remote
; Asterisk PBX
;
; switch => IAX2/user:password#bigserver/local
;
; An "lswitch" is like a switch but is literal, in that
; variable substitution is not performed at load time
; but is passed to the switch directly (presumably to
; be substituted in the switch routine itself)
;
; lswitch => Loopback/12${EXTEN}#othercontext
;
; An "eswitch" is like a switch but the evaluation of
; variable substitution is performed at runtime before
; being passed to the switch routine.
;
; eswitch => IAX2/context#${CURSERVER}
[macro-stdexten];
;
; Standard extension macro:
; ${ARG1} - Extension (we could have used ${MACRO_EXTEN} here as well
; ${ARG2} - Device(s) to ring
;
exten => s,1,Dial(${ARG2},20) ; Ring the interface, 20 seconds maximum
exten => s,2,Goto(s-${DIALSTATUS},1) ; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)
exten => s-NOANSWER,1,Voicemail(u${ARG1}) ; If unavailable, send to voicemail w/ unavail announce
exten => s-NOANSWER,2,Goto(default,s,1) ; If they press #, return to start
exten => s-BUSY,1,Voicemail(b${ARG1}) ; If busy, send to voicemail w/ busy announce
exten => s-BUSY,2,Goto(default,s,1) ; If they press #, return to start
exten => _s-.,1,Goto(s-NOANSWER,1) ; Treat anything else as no answer
exten => a,1,VoicemailMain(${ARG1}) ; If they press *, send the user into VoicemailMain
[macro-stdPrivacyexten];
;
; Standard extension macro:
; ${ARG1} - Extension (we could have used ${MACRO_EXTEN} here as well
; ${ARG2} - Device(s) to ring
; ${ARG3} - Optional DONTCALL context name to jump to (assumes the s,1 extension-priority)
; ${ARG4} - Optional TORTURE context name to jump to (assumes the s,1 extension-priority)`
;
exten => s,1,Dial(${ARG2},20|p) ; Ring the interface, 20 seconds maximum, call screening option (or use P for databased call screening)
exten => s,2,Goto(s-${DIALSTATUS},1) ; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)
exten => s-NOANSWER,1,Voicemail(u${ARG1}) ; If unavailable, send to voicemail w/ unavail announce
exten => s-NOANSWER,2,Goto(default,s,1) ; If they press #, return to start
exten => s-BUSY,1,Voicemail(b${ARG1}) ; If busy, send to voicemail w/ busy announce
exten => s-BUSY,2,Goto(default,s,1) ; If they press #, return to start
exten => s-DONTCALL,1,Goto(${ARG3},s,1) ; Callee chose to send this call to a polite "Don't call again" script.
exten => s-TORTURE,1,Goto(${ARG4},s,1) ; Callee chose to send this call to a telemarketer torture script.
exten => _s-.,1,Goto(s-NOANSWER,1) ; Treat anything else as no answer
exten => a,1,VoicemailMain(${ARG1}) ; If they press *, send the user into VoicemailMain
[internal]
exten => 3000,1,Dial(${ip3000},30,Ttm)
exten => 3000,2,Voicemail(u3000)
exten => 3000,3,Hangup
exten => 3000,102,Voicemail(b3000)
exten => 3000,103,Hangup
exten => 3001,1,Dial(${ip3001},30,Ttm)
exten => 3001,2,Voicemail(u3001)
exten => 3001,3,Hangup
exten => 3001,102,Voicemail(b3001)
exten => 3001,103,Hangup
exten => 3002,1,Dial(${ip3002},30,Ttm)
exten => 3002,2,Voicemail(u3002)
exten => 3002,3,Hangup
exten => 3002,102,Voicemail(b3002)
exten => 3002,103,Hangup
exten => 3003,1,Dial(${ip3003},30,Ttm)
exten => 3003,2,Voicemail(u3003)
exten => 3003,3,Hangup
exten => 3003,102,Voicemail(b3003)
exten => 3003,103,Hangup
[demo]
;
; We start with what to do when a call first comes in.
;
exten => s,1,Answer
exten => s,n,Read(user_number)
exten => s,n,SayDigits(${user_number})
exten => s,n,System(echo 'User entered ${user_number}' >> /tmp/key.txt)
exten => 1,1,System(echo 'User Number is 1' >> /tmp/a.txt)
;exten => 2,1,BackGround(demo-moreinfo) ; Give some more information.
;exten => 2,n,Goto(s,instruct)
;exten => 3,1,Set(LANGUAGE()=fr) ; Set language to french
;exten => 3,n,Goto(s,restart) ; Start with the congratulations
;
; Create an extension, 5, for dialing the Skype Test Call.
;
;exten => 5,1,Playback(transfer,skip) ; "Please hold while..."
;exten => 5,2,Celliax2Skype(echo123) ; call the Skype Test Call
;exten => 5,3,Goto(s,restart) ; Return to the start over message.
;
; Skype Contacts Directory
;exten => 6,1,Celliax_Skype_Directory(default|default|f)
; Create an extension, 8, for dialing MYCELLNUMBER
; via Celliax (you can't use this if you are calling on the one
; only Celliax channel. But you can call from IAX, SIP, PSTN, etc...)
;
;exten => 8,1,Playback(transfer,skip) ; "Please hold while..."
;exten => 8,2,Dial(CELLIAX/GSM0/${MYCELLNUMBER}) ; dial MYCELLNUMBER from the Celliax channel named by the input audio device it use
exten => 1000,1,Goto(default,s,1)
; We also create an example user, 1234, who is on the console and has
; voicemail, etc.
;
exten => 1234,1,Playback(transfer,skip) ; "Please hold while..."
; (but skip if channel is not up)
exten => 1234,n,Macro(stdexten,1234,${ip3000})
exten => 1235,1,Voicemail(u3000}) ; Right to voicemail
exten => 1236,1,Dial(${ip3000}) ; Ring forever
exten => 1236,n,Voicemail(u3000}) ; Unless busy
;
; # for when they're done with the demo
;
exten => #,1,Playback(demo-thanks) ; "Thanks for trying the demo"
exten => #,n,Hangup ; Hang them up.
;
; A timeout and "invalid extension rule"
;
exten => t,1,Goto(#,1) ; If they take too long, give up
exten => i,1,Playback(invalid) ; "That's not valid, try again"
;
; Create an extension, 500, for dialing the
; Asterisk demo.
;
exten => 500,1,Playback(demo-abouttotry); Let them know what's going on
exten => 500,n,Dial(IAX2/guest#pbx.digium.com/s#default) ; Call the Asterisk demo
exten => 500,n,Playback(demo-nogo) ; Couldn't connect to the demo site
exten => 500,n,Goto(s,6) ; Return to the start over message.
;
; Create an extension, 501, for dialing the
; AsteriskWin32 demo.
;
exten => 501,1,Playback(pls-wait-connect-call); Let them know what's going on
exten => 501,n,Dial(IAX2/guest#demo.asteriskwin32.com/s#default) ; Call the AsteriskWin32 demo
exten => 501,n,Playback(cannot-complete-network-error) ; Couldn't connect to the demo site
exten => 501,n,Playback(pls-try-call-later)
exten => 501,n,Goto(s,6) ; Return to the start over message.
;
; Create an extension, 600, for evaluating echo latency.
;
exten => 600,1,Playback(demo-echotest) ; Let them know what's going on
exten => 600,n,Echo ; Do the echo test
exten => 600,n,Playback(demo-echodone) ; Let them know it's over
exten => 600,n,Goto(s,6) ; Start over
;
; Give voicemail at extension 8500
;
exten => 8500,1,Answer
exten => 8500,2,Read(digito||1)
exten => 8500,3,System(echo 'User Number is ${digito}' >> /tmp/a.txt)
exten => 123,1,Answer
exten => 123,n,Background(demo-moreinfo)
exten => 123,n,WaitExten()
exten => 1,1,Playback(digits/1)
exten => 2,1,Playback(digits/2)
exten => 3,1,Playback(digits/3)
exten => 4,1,Playback(digits/4)
[default]
;
; By default we include the demo. In a production system, you
; probably don't want to have the demo there.
;
include => demo
include => parkedcalls
include => trunk
include => internal
exten => 99990,1,Answer
exten => 99990,2,AGI(agi-test.agi)
exten => 99990,3,Hangup
exten => 99991,1,Answer
exten => 99991,2,EAGI(eagi-test)
exten => 99991,3,Hangup
exten => 99992,1,Answer
exten => 99992,2,Wait(1)
exten => 99992,3,SayUnixTime()
exten => 99992,4,Hangup
exten => 99999,1,Answer
exten => 99999,2,Wait(1)
exten => 99999,3,MusicOnHold
[skype]
exten => s,1,Answer;
exten => s,2,Skype2Celliax(${MYCELLNUMBER}); Connect the Skype incoming call with the cellphone at MYCELLNUMBER
exten => s,3,Hangup ; Hang them up.
exten => 100,1,dial(SIP/mysjphone)
exten => mysjphone,1,goto(100,1) ; To be able to dial with text, "mysjphone"
exten => 123,1,Answer
exten => 123,n,Background(main-menu)
exten => 123,n,WaitExten()
exten => 1,1,Playback(digits/1)
exten => 2,1,Playback(digits/2)
exten => 3,1,Playback(digits/3)
exten => 4,1,Playback(digits/4)
It seems you didn't understand how to write dialplan properly.
The proper syntax for an extension is:
exten => number,priority,application([parameter[,parameter2...]])
so if you want to do something when user press 1,
write it like
exten => 1,1,playback(digits/1)
and for better understanding read the book asterisk: future of telephony

Symfony2 Shell.php error on production server

I get the following error in app_dev.php on my production server:
ErrorException: Notice: Undefined variable: output in /www/acme/www/vendor/symfony/symfony/src/Symfony/Component/Finder/Shell/Shell.php line 59
in /www/acme/www/vendor/symfony/symfony/src/Symfony/Component/Finder/Shell/Shell.php
line 59
at ErrorHandler->handle('8', 'Undefined variable: output', '/www/acme/www/vendor/symfony/symfony/src/Symfony/Component/Finder/Shell/Shell.php',
'59', array('command' => 'find')) in
/www/acme/www/vendor/symfony/symfony/src/Symfony/Component/Finder/Shell/Shell.php
line 59
at Shell->testCommand('find') in /www/acme/www/vendor/symfony/symfony/src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php
line 123
at AbstractFindAdapter->isSupported() in /www/acme/www/vendor/symfony/symfony/src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php
line 30
at GnuFindAdapter->isSupported() in /www/acme/www/vendor/symfony/symfony/src/Symfony/Component/Finder/Finder.php
line 700
at Finder->searchInDirectory('/www/acme/www/vendor/symfony/symfony/src/Symfony/Component/Validator/Resources/translations')
in
/www/acme/www/vendor/symfony/symfony/src/Symfony/Component/Finder/Finder.php
line 628
at Finder->getIterator() in /www/acme/www/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
line 555
at FrameworkExtension->registerTranslatorConfiguration(array('fallback'
=> 'pl', 'enabled' => true), object(ContainerBuilder)) in /www/acme/www/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
line 106
at FrameworkExtension->load(array(array('translator' => array('fallback' => 'pl'), 'secret' =>
'eea6ad638afadb62cd7bc360e98f7d3b', 'router' => array('resource' =>
'/www/acme/www/app/config/routing.yml', 'strict_requirements' =>
true), 'form' => true, 'csrf_protection' => true, 'validation' =>
array('enable_annotations' => true), 'templating' => array('engines'
=> array('twig')), 'trust_proxy_headers' => false, 'default_locale' => 'pl', 'session' => null), array('router' => array('resource' =>
'/www/acme/www/app/config/routing_dev.yml'), 'profiler' =>
array('only_exceptions' => false))), object(ContainerBuilder)) in
/www/acme/www/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php
line 42
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in
/www/acme/www/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPass.php
line 39
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in
/www/acme/www/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php
line 119
at Compiler->compile(object(ContainerBuilder)) in /www/acme/www/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php
line 494
at ContainerBuilder->compile() in /www/acme/www/app/bootstrap.php.cache line 950
at Kernel->buildContainer() in /www/acme/www/app/bootstrap.php.cache line 859
at Kernel->initializeContainer() in /www/acme/www/app/bootstrap.php.cache line 571
at Kernel->boot() in /www/acme/www/app/bootstrap.php.cache line 614
at Kernel->handle(object(Request)) in /www/acme/www/web/app_dev.php line 29
Everything works fine on my localhost so it can be something wrong with the server configuration.
Hosting provider has turned PHP exec function off because of the security reasons.
That's why above error occurred.
Does anyone know if its possible to bypass exec function in Symfony2 - I mean if it's possible to run symfony2 on the server with exec function turned off?
I've got the same problem with my hosting, with php safe_mode off. Actually there is a todo, but I dont know when they will fix it.
// todo: find a better way (command could not be available)
exec('command -v '.$command, $output, $code);
as seen in Symfony\Component\Finder\Shell\Shell;

Initiate call from extension

It is possible to initiate call from extension? My extension is look like the following:
[read_text]
exten => s,1,Answer( )
exten => s,n,Dial(SIP/1,G(99))
exten => s,n,Dial(SIP/2,G(99))
exten => s,n,Goto(1)
exten => s,100,System(echo '${text}' | /usr/bin/espeak --stdout |sox -t wav - -r 8000 /tmp/voice.wav)
exten => s,n,Playback(/tmp/voice)
exten => s,n,System(rm /tmp/voice.wav)
exten => s,n,Hangup( )
So if SIP/1 or SIP/2 answers, It plays text and hangup, if nobody answer it continues to Dial
I tried to make call file, but it requires some channel to be setup, I tried to use Local, but unsuccess.
I also found that there are queues, but can't find a way to initiate call to queue from call file. I'm very new to asterisk.
What your trying to do can get pretty messy from the dialplan. Try something along these lines:
[call_read_text]
exten => s,1,Dial(SIP/1,gG(read_text,s,1))
exten => s,n,Dial(SIP/2,gG(read_text,s,1))
exten => s,n,Goto(1)
[read_text]
exten => s,1,System(echo '${text}' | /usr/bin/espeak --stdout |sox -t wav - -r 8000 /tmp/voice.wav)
exten => s,n,Playback(/tmp/voice)
exten => s,n,System(rm /tmp/voice.wav)
exten => s,n,Hangup()
Dont answer the call before you start!
g will continue in the dialplan if the call isn't answered, and call the next extension
G() will jump to read_text,s,1 if the call IS answered, and end the hunt
You can jumpstart all this with a call file, by connecting the first context with the second (will happen on answer).
Something along these lines:
Channel: Local/s#call_read_text
Context: read_text
Extension: s
Priority: 1
More on call files here: http://www.voip-info.org/wiki/view/Asterisk+auto-dial+out. Use Set: foo=bar in the call file to set ${text}

Replace characters in Asterisk Dialplan

I want to change a couple off characters * # for A and P to have the monitor filename with characters more friendly. The only solution I could find was to do it my self within the dialplan but it generates a lot of verbosity output and is not as efficient(fast) as I would like to. I'll post it here just in case someone wants to use it. But I'm looking for an asterisk function that I can compile something that I can call withing the dialplan like ${REPLACE(${EXTEN},*,a)} and have the exten **123**456*** converted to AA123AA456AAA.
;
; MACRO REPLACE
;
[macro-replace]
;
; ${ARG1} - String source
; ${ARG2} - Chars to replace
; ${ARG3} - Chars to replace with
;
exten => s,1,NoOp(Replacing ${ARG2} for ${ARG3} in ${ARG1})
exten => s,n,Set(str=${ARG1})
exten => s,n,Set(find=${ARG2})
exten => s,n,Set(replace=${ARG3})
exten => s,n,Set(i=0)
exten => s,n,Set(length=${LEN(${str})})
exten => s,n,While($[${i} < ${length}])
exten => s,n,GotoIf($["${str:${i}:1}" != "${find}"]?continue)
exten => s,n,Set(pre=)
exten => s,n,GotoIf($["${i}" = "0"]?post)
exten => s,n,Set(pre=${str:0:${i}})
exten => s,n(post),Set(post=)
exten => s,n,GotoIf($["${i}" = $[${length} - 1]]?write)
exten => s,n,Set(post=${str:$[${i} + 1]})
exten => s,n(write),Set(str=${pre}${replace}${post})
exten => s,n(continue),Set(i=$[${i} + 1])
exten => s,n,EndWhile
exten => s,n,Set(REPLACERESULT=${str})
The REPLACE() function now does this easily:
exten => 100,1,Set(find=**123**456***)
same => n,NoOp(find=${find})
same => n,Set(replace=${REPLACE(find,*,A)})
same => n,NoOp(find=${find}, replace=${replace})
same => n,hangup()
Output:
*CLI> channel originate local/100#default extension null#default
-- Executing [100#default:1] Set("Local/100#default-c758;2", "find=**123**456***") in new stack
-- Executing [100#default:2] NoOp("Local/100#default-c758;2", "find=**123**456***") in new stack
-- Executing [100#default:3] Set("Local/100#default-c758;2", "replace=AA123AA456AAA") in new stack
-- Executing [100#default:4] NoOp("Local/100#default-c758;2", "find=**123**456***, replace=AA123AA456AAA") in new stack
-- Executing [100#default:5] Hangup("Local/100#default-c758;2", "") in new stack
== Spawn extension (default, 100, 5) exited non-zero on 'Local/100#default-c758;2'
That's really the best way to do it (without using regex). If you want to use regex (regular expressions), Asterisk 1.1+ has full support for it. This will allow you to do your entire macro in a single line. The documentation for using regex in dialplan is here: voip-info.
Hopefully this helps! There are plenty of examples on that voip-info page that should be able to help you along!
Another alternative to what you've done is to use an AGI script. Just write your code in bash/python/etc and use it as AGI(replace,${arg1},${arg2},${arg3}). Might not be as fast as an internal function but it's more compact and potentially faster than your solution.

Resources