bash shell variable not kept when run in opensips.cfg

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

bash shell variable not kept when run in opensips.cfg

Xavier Herlindo
Hello all,

this is my first post, so please bare with me if i commit any protocol error. All comments are welcome. Thanks all in advance for any help i can get.

I am running Opensips 8.1 with a Centos 5.8 install. I am setting up a redirect server. Only using the slo.so, mi_fifo.so, rr.so (not sure if i really need this one) and exec.so modules.

I am trying to run a simple bash script that checks if the number in the URI exists in a mysq table and if so, the script rewrites the prefix and ip address to redirect. If not, there is a default address to redirect to.

The sh script works fine as i have tested it directly from the shell, running without issues. If i input an URI with an existing number in my mysql table, the script connects to the db, validates it, an the output is the modified URI as expected. Now if the script is called from within opensips.cfg file, the script is not validating in mysql. The opensips log file show no errors when running the sh file. If i try to set an incorrect connection param string there is no change either, as if the line is ignored.

This is my unrecognized variable:

exec_query=`mysql -u USER --password=TEST -s -D MY_DB -e "SELECT numB FROM valid_numb WHERE numB = '123';"`

 If i echo the value for exec_query it is empty when running within opensips.cfg 
Running in the bash prompt the value of exec_query is set correctly.

This same shell script was tested in an old SER box without not issues, so i think it is something out of the script directly related to opensips configuration. 

Do you know what may be the problem?

Regards,

Xavier

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: bash shell variable not kept when run in opensips.cfg

Ali Pey
Hello Xavier,

Try the avops module. This is your best option in this scenario:


Regards,
Ali Pey

On Sat, Oct 6, 2012 at 7:38 PM, Xavier Herlindo <[hidden email]> wrote:
Hello all,

this is my first post, so please bare with me if i commit any protocol error. All comments are welcome. Thanks all in advance for any help i can get.

I am running Opensips 8.1 with a Centos 5.8 install. I am setting up a redirect server. Only using the slo.so, mi_fifo.so, rr.so (not sure if i really need this one) and exec.so modules.

I am trying to run a simple bash script that checks if the number in the URI exists in a mysq table and if so, the script rewrites the prefix and ip address to redirect. If not, there is a default address to redirect to.

The sh script works fine as i have tested it directly from the shell, running without issues. If i input an URI with an existing number in my mysql table, the script connects to the db, validates it, an the output is the modified URI as expected. Now if the script is called from within opensips.cfg file, the script is not validating in mysql. The opensips log file show no errors when running the sh file. If i try to set an incorrect connection param string there is no change either, as if the line is ignored.

This is my unrecognized variable:

exec_query=`mysql -u USER --password=TEST -s -D MY_DB -e "SELECT numB FROM valid_numb WHERE numB = '123';"`

 If i echo the value for exec_query it is empty when running within opensips.cfg 
Running in the bash prompt the value of exec_query is set correctly.

This same shell script was tested in an old SER box without not issues, so i think it is something out of the script directly related to opensips configuration. 

Do you know what may be the problem?

Regards,

Xavier

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users



_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: bash shell variable not kept when run in opensips.cfg

osiris123d
In reply to this post by Xavier Herlindo
It sounds like you are trying to reinvent the wheel.  Why not just use the http://www.opensips.org/html/docs/modules/1.8.x/db_mysql.html module so you can query your database.  And then like Ali says you can use AVPOPS module with a little scripting in the OpenSIPS config.  You really don't need to use exec.so for what you want to do.



On Sat, Oct 6, 2012 at 6:38 PM, Xavier Herlindo <[hidden email]> wrote:
Hello all,

this is my first post, so please bare with me if i commit any protocol error. All comments are welcome. Thanks all in advance for any help i can get.

I am running Opensips 8.1 with a Centos 5.8 install. I am setting up a redirect server. Only using the slo.so, mi_fifo.so, rr.so (not sure if i really need this one) and exec.so modules.

I am trying to run a simple bash script that checks if the number in the URI exists in a mysq table and if so, the script rewrites the prefix and ip address to redirect. If not, there is a default address to redirect to.

The sh script works fine as i have tested it directly from the shell, running without issues. If i input an URI with an existing number in my mysql table, the script connects to the db, validates it, an the output is the modified URI as expected. Now if the script is called from within opensips.cfg file, the script is not validating in mysql. The opensips log file show no errors when running the sh file. If i try to set an incorrect connection param string there is no change either, as if the line is ignored.

This is my unrecognized variable:

exec_query=`mysql -u USER --password=TEST -s -D MY_DB -e "SELECT numB FROM valid_numb WHERE numB = '123';"`

 If i echo the value for exec_query it is empty when running within opensips.cfg 
Running in the bash prompt the value of exec_query is set correctly.

This same shell script was tested in an old SER box without not issues, so i think it is something out of the script directly related to opensips configuration. 

Do you know what may be the problem?

Regards,

Xavier

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users




--
--
*--*--*--*--*--*
Duane
*--*--*--*--*--*
--

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: bash shell variable not kept when run in opensips.cfg

Xavier Herlindo
In reply to this post by Ali Pey
Thank you Ali, for your prompt response. I will read about it to implement it. 

Still i am a bit puzzled as why this is not working in such a simple scenario. It worked in the old SER box.

Regards,

Xavier


De: Ali Pey <[hidden email]>
Para: Xavier Herlindo <[hidden email]>; OpenSIPS users mailling list <[hidden email]>
Enviado: Sábado, 6 de octubre, 2012 19:09:40
Asunto: Re: [OpenSIPS-Users] bash shell variable not kept when run in opensips.cfg

Hello Xavier,

Try the avops module. This is your best option in this scenario:


Regards,
Ali Pey

On Sat, Oct 6, 2012 at 7:38 PM, Xavier Herlindo <[hidden email]> wrote:
Hello all,

this is my first post, so please bare with me if i commit any protocol error. All comments are welcome. Thanks all in advance for any help i can get.

I am running Opensips 8.1 with a Centos 5.8 install. I am setting up a redirect server. Only using the slo.so, mi_fifo.so, rr.so (not sure if i really need this one) and exec.so modules.

I am trying to run a simple bash script that checks if the number in the URI exists in a mysq table and if so, the script rewrites the prefix and ip address to redirect. If not, there is a default address to redirect to.

The sh script works fine as i have tested it directly from the shell, running without issues. If i input an URI with an existing number in my mysql table, the script connects to the db, validates it, an the output is the modified URI as expected. Now if the script is called from within opensips.cfg file, the script is not validating in mysql. The opensips log file show no errors when running the sh file. If i try to set an incorrect connection param string there is no change either, as if the line is ignored.

This is my unrecognized variable:

exec_query=`mysql -u USER --password=TEST -s -D MY_DB -e "SELECT numB FROM valid_numb WHERE numB = '123';"`

 If i echo the value for exec_query it is empty when running within opensips.cfg 
Running in the bash prompt the value of exec_query is set correctly.

This same shell script was tested in an old SER box without not issues, so i think it is something out of the script directly related to opensips configuration. 

Do you know what may be the problem?

Regards,

Xavier

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users





_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: bash shell variable not kept when run in opensips.cfg

Xavier Herlindo
In reply to this post by osiris123d
Thanks Duane for your comment. 

I just read about mysql and AVPops  modules and I can see your point. It happens that this script was already working in a friends box using SER and i just tried to reuse it. I will work on setting this in the way you suggest. Although my first approach was quite simple, i guess the OpenSIPS way must be even easier. =)

Regards,

Xavier

De: Duane Larson <[hidden email]>
Para: Xavier Herlindo <[hidden email]>; OpenSIPS users mailling list <[hidden email]>
Enviado: Sábado, 6 de octubre, 2012 19:15:36
Asunto: Re: [OpenSIPS-Users] bash shell variable not kept when run in opensips.cfg

It sounds like you are trying to reinvent the wheel.  Why not just use the http://www.opensips.org/html/docs/modules/1.8.x/db_mysql.html module so you can query your database.  And then like Ali says you can use AVPOPS module with a little scripting in the OpenSIPS config.  You really don't need to use exec.so for what you want to do.



On Sat, Oct 6, 2012 at 6:38 PM, Xavier Herlindo <[hidden email]> wrote:
Hello all,

this is my first post, so please bare with me if i commit any protocol error. All comments are welcome. Thanks all in advance for any help i can get.

I am running Opensips 8.1 with a Centos 5.8 install. I am setting up a redirect server. Only using the slo.so, mi_fifo.so, rr.so (not sure if i really need this one) and exec.so modules.

I am trying to run a simple bash script that checks if the number in the URI exists in a mysq table and if so, the script rewrites the prefix and ip address to redirect. If not, there is a default address to redirect to.

The sh script works fine as i have tested it directly from the shell, running without issues. If i input an URI with an existing number in my mysql table, the script connects to the db, validates it, an the output is the modified URI as expected. Now if the script is called from within opensips.cfg file, the script is not validating in mysql. The opensips log file show no errors when running the sh file. If i try to set an incorrect connection param string there is no change either, as if the line is ignored.

This is my unrecognized variable:

exec_query=`mysql -u USER --password=TEST -s -D MY_DB -e "SELECT numB FROM valid_numb WHERE numB = '123';"`

 If i echo the value for exec_query it is empty when running within opensips.cfg 
Running in the bash prompt the value of exec_query is set correctly.

This same shell script was tested in an old SER box without not issues, so i think it is something out of the script directly related to opensips configuration. 

Do you know what may be the problem?

Regards,

Xavier

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users




--
--
*--*--*--*--*--*
Duane
*--*--*--*--*--*
--



_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users