Monday, March 25, 2019

Asterisk PBX common errors and Solution

Asterisk PBX common errors and Solution


1. Got this error during IAX2 communication, for Asterisk to Asterisk communication

[Mar 26 11:36:48] WARNING[4529][C-00000002]: /usr/src/asterisk-certified-13.21-cert3/include/asterisk/crypto.h:147 __stub__ast_aes_set_encrypt_key: AES encryption disabled. Install OpenSSL.
[Mar 26 11:36:48] WARNING[4529][C-00000002]: /usr/src/asterisk-certified-13.21-cert3/include/asterisk/crypto.h:159 __stub__ast_aes_set_decrypt_key: AES encryption disabled. Install OpenSSL.
[Mar 26 11:36:48] WARNING[4529][C-00000002]: /usr/src/asterisk-certified-13.21-cert3/include/asterisk/crypto.h:159 __stub__ast_aes_set_decrypt_key: AES encryption disabled. Install OpenSSL.
    -- Hungup 'IAX2/receiver-14602'


Solution:
  1. yum install openssl openssl-devel 
  2. Compile, make menuselect with Resource Module->res_crypto enabled and Install asterisk
  3. Load res_crypto module if not loaded by default (module load res_crypto)

Thursday, October 18, 2018

Installing PHP 7.2.11 in CentOS 7.4 with Pthreads enabled

Installing PHP 7.2.11 in CentOS 7.4 with pthreads enabled

This steps are meant for PHP CLI threading applications.  So web related appications are not installed along with.

OS Version: CentOS Linux release 7.4.1708 (Core)

First we need to install  PHP. Version used is php-7.2.11

1. Download php-7.2.11.tar.gz source from http://php.net/get/php-7.2.11.tar.gz/from/a/mirror
2. Extract to /usr/src
 
3. cd /usr/src/php-7.2.11
4. ./configure --with-config-file-path=/usr/local/lib --with-tsrm-pthreads --enable-pthreads=shared --enable-maintainer-zts --enable-sockets
5. make
6. make test
7. make install
8. To see the php version installed
     php -v

Now we need to install Pthreads. Source is taken from Github.

1. Download from https://github.com/krakjoe/pthreads.git
2. Extract to /usr/src/php-7.2.11/ext
3. This step may not be required, but this is how it got worked for me and i didnt tried the other way.      Rename the extracted file from pthreads-master to pthreads.
      mv /usr/src/php-7.2.11/ext/pthreads-master /usr/src/php-7.2.11/ext/pthreads
4. cd /usr/src/php-7.2.11/ext/pthreads
5. phpize
6. ./configure
7. make
8. make test
9. make install

Now we require to Rebuild our PHP installation

1. cd /usr/src/php-7.2.11
2. make clean
3. rm -f configure && ./buildconf --force
4. ./configure --with-config-file-path=/usr/local/lib --with-tsrm-pthreads --enable-pthreads=shared --enable-maintainer-zts --enable-sockets
5. make
6. make test
7. make install
   At end of make install note this path
    Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-zts-20170718/

Next is the important and final step, to edit the configuration file (php.ini)
1. Give command -> php --ini
   Output ->
    Configuration File (php.ini) Path: /usr/local/lib
    Loaded Configuration File:         (none)
    Scan for additional .ini files in: (none)
    Additional .ini files parsed:      (none)

2. Copy file from /usr/src/php-7.2.11 to /usr/local/lib and rename the file to php.ini
    cp /usr/src/php-7.2.11/php.ini-development /usr/local/lib/php.ini

3. Give command -> php --ini
   Output ->
    Configuration File (php.ini) Path: /usr/local/lib
    Loaded Configuration File:         /usr/local/lib/php.ini
    Scan for additional .ini files in: (none)
    Additional .ini files parsed:      (none)

   Now the Configuration file is loaded

4. Add this line to /usr/local/lib/php.ini below
    extension=/usr/local/lib/php/extensions/no-debug-zts-20170718/pthreads.so



5. Shows the modules loaded
     php -m

    In the loaded modules you shoud be able to see the pthreads


Thursday, June 7, 2018

Steps for importing csv / text data to Postgres database table in Ubuntu / Linux

Steps for importing csv / text data to Postgres database table in Ubuntu / Linux


  • If the file is too big to process in one step, cut the file into multiple files
    • split -l 250000 filename.txt  // Will split the file into multiple files with 250000 lines
  • In case if all columns are not required to be imported, create a new file with required number of columns. Mind the delimiter used.
    • cut -d'|' -f1,3,6,33,34,35 file_name.txt >> out.txt
  • Next two lines are specific to my case
    • sed -e '/^[a-z,A_Z]/d' test.txt > test_1.txt  // To delete the lines which starts with a character.
    • sed -i '/^$/d' file.txt   //To delete empty lines
  • Copy the first line which is the column names to all the splitted file outputs, except the first file. Use "vim".
  • I used a python program to delete lines which contains number of columns not equal to three.
#Python Program
fh = open('test.txt')      # Open the Original file
f = open("test_2.txt","w") # Create a new file to store the output
for line in fh:
    countLine = line.count("|")
    if countLine == 2:
       f.write(line)
fh.close()
  • Create a table with requited columns. Better to give data type as character varying and size as larger than reqired for all columns (eg character varying (400))
  • Copy the formatted txt / csv to postgres table. Here delimiter used is '|'.
    • COPY table_name(phone_no,subscriber_name,address,pincode,place,district) FROM 'local_location/filename.txt' DELIMITER '|' CSV HEADER;
  • Possible Errors
    • Error telling some special characters present, so not able to copy.  /*  "UTF8": 0xbf   */
    • Here i have deleted the lines with that special characters. Go this website and figure out the special character.
    • https://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=0x       ¿
    • Using vim editor search for the special character in file and delete it manually.
  • After copying the file, do the required process in the table
    • --delete FROM table_name WHERE length(phone_no)!=10;
    • --delete FROM table_name WHERE length(phone_no)=0;
    • --delete FROM table_name WHERE phone_no is null
    • --delete FROM table_name WHERE length(subscriber_name)>95;
    • --delete FROM table_name WHERE length(address)>295;
  • Alter the column datatype to required one
    • ALTER TABLE table_name ALTER COLUMN phone_no TYPE bigint USING (phone_no::bigint);  //Column name is phone_no
  • Fill unfilled column in database table with value from another column, delemited value
    • update table_name set pincode = ( SELECT split_part(address, '!', 3));
  • Update Column by replacing occurance of a string
    • UPDATE SET = REPLACE ( , 'string1', 'string2' );

Steps for take postgres table dump and import to another Postgres database

  • Login as root user
    • sudo su
  • Login as postgres user
    • su - postgres
  • Take dump of the table to file named output.sql
    • pg_dump -p 5432 --column-inserts --data-only --table=table_name database_name > output.sql
  • Copy output.sql to postgres/data folder of the machine where it is to be ported.
  • Create table at destination with same table name and properties
  • Go inside the /postgres/data folder and give this command
    • psql -p 5444 -d database_name -f output.sql  
      • -p is for port number
      • -d for database name

Tuesday, September 1, 2015

Garmin GPS 18x USB with Ubuntu

1. Install GPS babel, driver for the garmin device
      sudo apt-get install gpsbabel

2. dmesg to the device is detected

3. lsusb

4. ls -l /dev/bus/usb/001/002

5. sudo adduser ubuntu lp

6. modprobe -r garmin_gps

7. gpsbabel -T -i garmin -f usb: -o kml -F xxx.kml

8. Give permission to normal user in Ubuntu for using GPSBabel

    sudo /etc/udev/rules.d/51-garmin.rules

    Enter this line and save file

   SYSFS{idVendor}=="091e", SYSFS{idProduct}=="0003", MODE="666"


GSM AF-007 Modem with Ubuntu 

1. apt-get install gammu

2. gammu-config

   a. set port to /dev/ttyUSB0
   b. Connection to at115200
   C. Save setting

3.gammu sendsms TEXT 09790847087 -text "Lati:15.76454 Longi:9.07564356" 

Monday, August 31, 2015

Install Ubuntu in Beaglebone Black and setup network with Ethernet connection


Installation of Ubuntu in BBB

1. Download prebuilt image of Ubuntu (*.img.xz) from http://elinux.org/BeagleBoardUbuntu#eMMC:_BeagleBone_Black

2. Extract the image

3. Write image to a microSD card using Win32DiskImager (Used Windows 7 Professional).

4. Insert the SD card into poweredoff beaglebone. Keep pressed the boot button and Power on the board (used 5 V adapter to Power ON).

5. Keep the boot button pressed till the indicator leds start blinking. Wait for about 10 to 15 min till all the indicator leds stays ON.

6. Power off the board, take out the SD card and power it on again with USB connected to your computer (Can remove the 5 V adapter now).

7. ssh to ubuntu@192.168.7.2 using terminal in linux or putty in windows. Password is "temppwd".

8. You are logged in to the Ubuntu OS in Beaglebone black.

Setup Network with Ethernet connection

The set up explained here is specific for my network, where  a static ip is set to the beagle board.

1. Connect power, usb and ethernet cable to BBB.

2. ssh to the board with 192.168.7.2 (for usb connection)
      ssh ubuntu@192.168.7.2
      password: temppwd

3.  Set static IP to the primary n/w interface, which is eth0.
       a. nano /etc/network/interface
       b. Add below lines in primary n/w interface part
             # The primary network interface
             auto eth0
             iface eth0 inet static
                address 10.184.36.6  // Contact system admin for ip informations.
                netmask 255.255.255.0
                gateway 10.184.36.1

4. Now logout of the terminal and ssh to the board with 10.184.36.6 (assigned static IP)
      ssh ubuntu@10.184.36.6
      password: temppwd

5. Assign name server (This step is needed to be done each time the BBB is rebooted, Or else do something to make this change permanent).
      a. nano /etc/resolv.conf
      b. Commend all lines and add below line
            nameserver 10.184.0.11 // Contact system admin for ip informations.

6. Update by giving below command and enjoy.
      sudo apt-get update

Friday, August 21, 2015

Linux useful commands and informations

1. In debian based OS apt-get install command will download the .deb package in the below folder before installation.

    /var/cache/apt/archives/

2. To format disk in commandline

      sudo cfdisk /dev/sdb

   One another option is

     sudo mkfs.ext4 /dev/sdb1

3. Find User ID (uid) of the current user in Linux system.

      id -u [USER_NAME]

      eg:  id -u root  (which will be 0).

4. Change ownership of a folder for specific user.

      chown -R [UID_OF_USER] [PATH_TO _FOLDER]

      eg: chown -R 1000 /opt/tinyos-2.x/

5. Find a file or directory in specific place.

      find [PATH_TO_SEARCH] -name [FILE_NAME]

      eg: find /opt -name tinyos.sh

6. Install grub due to some error in grub.

      grub-install --root-directory=/dev/sda

7. Write OS image (*.img) into USB/ microSD in linux (Ubuntu).
     Create bootable USB/ microSD from image file (.img)

      sudo dd if=./BBB*.img of=/dev/sdX

      sdX, here X denote where the device is mounted.

8. SSh connection failure due to the error "Host key verification failed."

     ssh-keygen -R



9. Find baud rate of a serial device through commanline

    sudo stty -F /dev/ttyUSB0    //replace ttyUSB0

Monday, June 1, 2015

PostgreSQL Useful commands


PostgreSQL Useful commands

  • To copy a table to create new one
    • CREATE TABLE table_name_2 ( like table_name_2 including all)
  • Insert columns from one table to another
    • insert into table_name (phone_no,subscriber_name,address,pincode,place,district) select phone_no,subscriber_name,address,pincode,place,district from tabele_2;
  • Insert column of one table from another table, where second table colum length is less than 95
    • insert into table_back 
    • (
    •   phone_no,subscriber_name,address,pincode,place,district
    • ) select phone_no,subscriber_name,address,pincode,place,district from table_2 where length (subscriber_name) > 95;
  • Delete complete content from table
    • DELETE FROM table_name;
  • Delete a column from table
    • DELETE FROM table_name WHERE phone_no = 7382613796;
  • Change table name
    • ALTER TABLE table_name RENAME TO TABLE_NAME_2;
  • Change column datatype
    • ALTER TABLE table_name ALTER COLUMN phone_no TYPE bigint USING (phone_no::bigint); 
      • phone_no is the column name.
  • Delete row when length of a column not equal to 10
    • delete FROM table_name WHERE length(phone_no)!=10;
  • Update column by its first n characters, if the character length is to be reduced
    • update test_1 set subscriber_name = left(subscriber_name,10);
  • To create new table from old table, sorted by systemtime
    • create table new_racktemp as select * from racktemp order by systemtime;
  • Alter/ Update existing table by inserting new column, setting it with primary key and insert the column with serial numbers starting from 1.
    • alter table new_racktemp add column slno bigserial primary key;
  • For creating sequence number and updating column with that (not tested)
    • CREATE SEQUENCE seq;
    • ALTER SEQUENCE seq RESTART WITH 1;
    • UPDATE racktemp SET slno=nextval('seq');
  • Dump and restore for command line
    • Go to "cmd"
    • Change directory to the Postgres Bin folder      
    • cd // cd C:\Program Files\PostgreSQL\9.3\bin
    • Use pg_dump to backup
      • pg_dump.exe -U postgres -t "table_name" "Data_base_name" > "Path&Name_Backup"
      • //pg_dump.exe -U postgres -t consotable hpc > C:\Users\CFD\Desktop\consot.backup
  • Use psql to restore to another database
    • psql.exe -U postgres "DB_name" < "Path for backup file"
    • //psql.exe -U postgres testdb < C:\Users\CFD\Desktop\consot.backup
  • Get values of the last updated row inreference to serial number
    • SELECT * from table_name order by slno desc limit 1