Archive for June 27th, 2014

Unix shell: list directories only

Friday, June 27th, 2014

A simple question with the answer not so simple to find.
For a current directory:

lexus@lexus:~$ ls -dl */
drwxr-xr-x 16 lexus lexus 4096 Apr  1 16:16 KAZANTSEV/
drwxrwxr-x  3 lexus lexus 4096 Aug  5  2013 Storage/
drwxrwxr-x  2 lexus lexus 4096 Feb  9  2012 Ubuntu One/
drwxr-xr-x 11 lexus lexus 4096 Jan  3 17:14 VirtualBox VMs/
drwxrwxr-x  2 lexus lexus 4096 Jun 10 17:09 dbn/
drwxr-xr-x  2 lexus lexus 4096 Jan 10 10:41 dwhelper/
drwxr-xr-x  3 lexus lexus 4096 May  2  2012 fluxmenu/
drwxr-xr-x  2 lexus lexus 4096 Feb  5 15:28 fontconfig/
drwxrwxr-x  2 lexus lexus 4096 Apr 18 17:24 images/
drwxr-xr-x  6 lexus lexus 4096 Oct 31  2013 sipvicious-0.2.8/
lexus@lexus:~$ 

For some other directory:

lexus@lexus:~$ ls -dl /tmp/*/
drwx------ 2 lexus lexus 4096 May 30 07:08 /tmp/CRX_75DAF8CB7768/
drwx------ 2 lexus lexus 4096 Jun 26 12:23 /tmp/acroread_1000_1000/
drwxr-xr-x 2 lexus lexus 4096 Jun 18 16:52 /tmp/hsperfdata_lexus/
drwx------ 2 lexus lexus 4096 Jun 25 18:36 /tmp/libgksu-lBNuPo/
drwx------ 2 lexus lexus 4096 Jun  6 14:57 /tmp/mc-lexus/
drwx------ 2 lexus lexus 4096 Jan  1  1970 /tmp/orbit-lexus/
drwx------ 2 root  root  4096 Jan  1  1970 /tmp/orbit-root/
drwx------ 2 lexus lexus 4096 Jun 11 16:48 /tmp/plugtmp/
drwx------ 2 lexus lexus 4096 May 26 17:59 /tmp/ssh-ftcIDV2jxXYG/
drwx------ 2 lexus lexus 4096 May 26 17:59 /tmp/ssh-tzuelndrwY3i/
lexus@lexus:~$

Brute your trunks, dial out

Friday, June 27th, 2014

A small snippet of dialplan how to dial if some trunk is not reachable.

Imagine, we have two SIP-trunks to dial out – [trunk1] and [trunk2]. You have to set ‘qualify=yes’ for both, otherwise this method will not work.
We’ll use the SIPPEER function with the ‘status’ argument:

; Func SIPPEER
exten => 401040,NoOp
    same => n,NoOp( [trunk1] SIPPEER info: ${SIPPEER(trunk1,status)})
    same => n,NoOp( ;===================================== )
    same => n,NoOp( [trunk2] SIPPEER info: ${SIPPEER(trunk2,status)})
    same => n,NoOp( ;===================================== )
    same => n,GotoIf($[${SIPPEER(trunk1,status)}= "OK"]?t1dial:t2)
    same => n(t1dial),Dial(SIP/trunk1/${EXTEN},5)
    same => n,Hangup
    same => n(t2),NoOp( [trunk1] is UNREACHABLE, trying [trunk2] in 1 second ... )
    same => n,Wait(1)
    same => n,GotoIf($[${SIPPEER(trunk2,status)}= "OK"]?t2dial:hang)
    same => n(t2dial),Dial(SIP/trunk2/${EXTEN},5)
    same => n,Hangup
    same => n(hang),Playback(have-a-rest)
    same => n,Hangup