Getting value from shell scripts
Hi, I have wrote a shell script and defined in exec module. exec get_streaming_data_usage { wait = yes program = "/bin/bash /scripts/get_streaming_data_usage.sh %{Framed-IP-Address}" input_pairs = request #output_pairs = reply shell_escape = yes #output = file } And I am executing in /usr/local/etc/raddb/sites-enabled/default get_streaming_data_usage Script is as follows: [root@freeradius ~]# cat /scripts/get_streaming_data_usage.sh #/bin/bash #get the framed IP_address: framed_ip_address = $1 #Get the usage in bytes: data_usage = `grep "$framed_ip_address" /scripts/user-bandwidth.txt | cut -d , -f 4` How can I get the value of data_usage inside the file /usr/local/etc/raddb/sites-enabled/default Please help -- Randeep Mob: +919447831699[kerala] Mob: +919880050349[B'lore] http://twitter.com/Randeeppr http://in.linkedin.com/in/randeeppr [image: --] Randeep Raman [image: http://]about.me/Randeeppr <http://about.me/Randeeppr>
On Thu, Oct 22, 2015 at 3:34 PM, Randeep <randeep123@gmail.com> wrote:
Hi,
I have wrote a shell script and defined in exec module.
Script is as follows: [root@freeradius ~]# cat /scripts/get_streaming_data_usage.sh #/bin/bash
#get the framed IP_address: framed_ip_address = $1 #Get the usage in bytes: data_usage = `grep "$framed_ip_address" /scripts/user-bandwidth.txt | cut -d , -f 4`
How can I get the value of data_usage inside the file /usr/local/etc/raddb/sites-enabled/default
Have you read the documentation? It should be included within your installation. The online verison for 3.0.9: http://networkradius.com/doc/3.0.9/raddb/mods-available/exec.html https://github.com/FreeRADIUS/freeradius-server/blob/v3.0.x/scripts/exec-pro... Short version: - do NOT commment out output_pairs - See "echo"s at the end of the example -- Fajar
Hi Fajar, Thanks for the links. I'm using the version 3.0.8 and documentation is same. The example you have given is to send parameters in the reply. But my case is different. I need to get this value from the script to the default file and do a comparison there and if the total data crosses the maximum data allowed then send a FUP rate-limit. Tmp-Integer-0 := "%{sql:SELECT (SUM(acctinputoctets)+SUM(acctoutputoctets)) AS Total FROM radacct where radacct.username='%{User-Name}'}" #Value of Max-Data from the radgroupcheck for the group of the user Tmp-Integer-1 := "%{sql: SELECT radgroupcheck.value FROM radusergroup INNER JOIN radgroupcheck ON radusergroup.groupname = radgroupcheck.groupname WHERE radusergroup.username='%{User-Name}' AND radgroupcheck.attribute='Max-Data'}" date_usage(from script) + Tmp-Integer-0 > Tmp-Integer-1 then apply FUP date_usage(from script) + Tmp-Integer-0 < Tmp-Integer-1 then dont apply FUP Or are you saying that I can just create some temp variable in default file and echo the value of data_usage to it? I have changed the values of output_pairs and ouput to none. Regards, Randeep On Thu, Oct 22, 2015 at 2:15 PM, Fajar A. Nugraha <list@fajar.net> wrote:
On Thu, Oct 22, 2015 at 3:34 PM, Randeep <randeep123@gmail.com> wrote:
Hi,
I have wrote a shell script and defined in exec module.
Script is as follows: [root@freeradius ~]# cat /scripts/get_streaming_data_usage.sh #/bin/bash
#get the framed IP_address: framed_ip_address = $1 #Get the usage in bytes: data_usage = `grep "$framed_ip_address" /scripts/user-bandwidth.txt | cut -d , -f 4`
How can I get the value of data_usage inside the file /usr/local/etc/raddb/sites-enabled/default
Have you read the documentation? It should be included within your installation.
The online verison for 3.0.9: http://networkradius.com/doc/3.0.9/raddb/mods-available/exec.html
https://github.com/FreeRADIUS/freeradius-server/blob/v3.0.x/scripts/exec-pro...
Short version: - do NOT commment out output_pairs - See "echo"s at the end of the example
-- Fajar - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
-- Randeep Mob: +919447831699[kerala] Mob: +919880050349[B'lore] http://twitter.com/Randeeppr http://in.linkedin.com/in/randeeppr [image: --] Randeep Raman [image: http://]about.me/Randeeppr <http://about.me/Randeeppr>
On Thu, Oct 22, 2015 at 4:39 PM, Randeep <randeep123@gmail.com> wrote:
date_usage(from script) + Tmp-Integer-0 > Tmp-Integer-1 then apply FUP date_usage(from script) + Tmp-Integer-0 < Tmp-Integer-1 then dont apply FUP
Or are you saying that I can just create some temp variable in default file and echo the value of data_usage to it?
Did you read the last four lines from the second link? -- Fajar
Yes I did. echo "Reply-Message += \"Hello, %u\"," echo "Reply-Message += \"PATH=$PATH\"," echo Framed-IP-Address = 255.255.255.255 exit 0 I'm not getting it. Please help. On Thu, Oct 22, 2015 at 3:17 PM, Fajar A. Nugraha <list@fajar.net> wrote:
On Thu, Oct 22, 2015 at 4:39 PM, Randeep <randeep123@gmail.com> wrote:
date_usage(from script) + Tmp-Integer-0 > Tmp-Integer-1 then apply FUP date_usage(from script) + Tmp-Integer-0 < Tmp-Integer-1 then dont apply FUP
Or are you saying that I can just create some temp variable in default file and echo the value of data_usage to it?
Did you read the last four lines from the second link?
-- Fajar - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
-- Randeep Mob: +919447831699[kerala] Mob: +919880050349[B'lore] http://twitter.com/Randeeppr http://in.linkedin.com/in/randeeppr [image: --] Randeep Raman [image: http://]about.me/Randeeppr <http://about.me/Randeeppr>
On Thu, Oct 22, 2015 at 4:52 PM, Randeep <randeep123@gmail.com> wrote:
Yes I did.
echo "Reply-Message += \"Hello, %u\"," echo "Reply-Message += \"PATH=$PATH\"," echo Framed-IP-Address = 255.255.255.255 exit 0
I'm not getting it.
Those are attributes that would go to reply (i.e. sent from radius to the NAS). Remeber "output_pairs = reply"? If by "apply FUP" you mean "have X attribute in reply items with value Y", then simply echo X = Y If you DON'T want to apply FUP, you don't echo that. It should be that simple. -- Fajar
No fajar. I have wrote a comparison in default file. I wrote this script only to get a value from a file which will be created by Mikrotik nas. After reading this value and doing the comparison, function in the default file will send a coa update to apply FUP. Regards, Randeep On Thu, Oct 22, 2015 at 3:26 PM, Fajar A. Nugraha <list@fajar.net> wrote:
On Thu, Oct 22, 2015 at 4:52 PM, Randeep <randeep123@gmail.com> wrote:
Yes I did.
echo "Reply-Message += \"Hello, %u\"," echo "Reply-Message += \"PATH=$PATH\"," echo Framed-IP-Address = 255.255.255.255 exit 0
I'm not getting it.
Those are attributes that would go to reply (i.e. sent from radius to the NAS). Remeber "output_pairs = reply"?
If by "apply FUP" you mean "have X attribute in reply items with value Y", then simply
echo X = Y
If you DON'T want to apply FUP, you don't echo that. It should be that simple.
-- Fajar - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
-- Randeep Mob: +919447831699[kerala] Mob: +919880050349[B'lore] http://twitter.com/Randeeppr http://in.linkedin.com/in/randeeppr [image: --] Randeep Raman [image: http://]about.me/Randeeppr <http://about.me/Randeeppr>
Then on your script, simply echo Attribute-Name = Some-Value The config SHOULD then be able to use &<list>:Attribute-Name where "list" is "reply". You DO know about unlang, don't you? http://freeradius.org/radiusd/man/unlang.html Look for "ATTRIBUTE REFERENCES". On Thu, Oct 22, 2015 at 5:00 PM, Randeep <randeep123@gmail.com> wrote:
No fajar.
I have wrote a comparison in default file.
I wrote this script only to get a value from a file which will be created by Mikrotik nas.
After reading this value and doing the comparison, function in the default file will send a coa update to apply FUP.
Regards, Randeep
On Thu, Oct 22, 2015 at 3:26 PM, Fajar A. Nugraha <list@fajar.net> wrote:
On Thu, Oct 22, 2015 at 4:52 PM, Randeep <randeep123@gmail.com> wrote:
Yes I did.
echo "Reply-Message += \"Hello, %u\"," echo "Reply-Message += \"PATH=$PATH\"," echo Framed-IP-Address = 255.255.255.255 exit 0
I'm not getting it.
Those are attributes that would go to reply (i.e. sent from radius to the NAS). Remeber "output_pairs = reply"?
If by "apply FUP" you mean "have X attribute in reply items with value Y", then simply
echo X = Y
If you DON'T want to apply FUP, you don't echo that. It should be that simple.
-- Fajar - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
-- Randeep Mob: +919447831699[kerala] Mob: +919880050349[B'lore] http://twitter.com/Randeeppr http://in.linkedin.com/in/randeeppr
[image: --] Randeep Raman [image: http://]about.me/Randeeppr <http://about.me/Randeeppr> - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
No. I'm new to this. Reading it. Thanks. On Thu, Oct 22, 2015 at 3:38 PM, Fajar A. Nugraha <list@fajar.net> wrote:
Then on your script, simply echo Attribute-Name = Some-Value
The config SHOULD then be able to use &<list>:Attribute-Name where "list" is "reply".
You DO know about unlang, don't you? http://freeradius.org/radiusd/man/unlang.html
Look for "ATTRIBUTE REFERENCES".
On Thu, Oct 22, 2015 at 5:00 PM, Randeep <randeep123@gmail.com> wrote:
No fajar.
I have wrote a comparison in default file.
I wrote this script only to get a value from a file which will be created by Mikrotik nas.
After reading this value and doing the comparison, function in the default file will send a coa update to apply FUP.
Regards, Randeep
On Thu, Oct 22, 2015 at 3:26 PM, Fajar A. Nugraha <list@fajar.net> wrote:
On Thu, Oct 22, 2015 at 4:52 PM, Randeep <randeep123@gmail.com> wrote:
Yes I did.
echo "Reply-Message += \"Hello, %u\"," echo "Reply-Message += \"PATH=$PATH\"," echo Framed-IP-Address = 255.255.255.255 exit 0
I'm not getting it.
Those are attributes that would go to reply (i.e. sent from radius to the NAS). Remeber "output_pairs = reply"?
If by "apply FUP" you mean "have X attribute in reply items with value Y", then simply
echo X = Y
If you DON'T want to apply FUP, you don't echo that. It should be that simple.
-- Fajar - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
-- Randeep Mob: +919447831699[kerala] Mob: +919880050349[B'lore] http://twitter.com/Randeeppr http://in.linkedin.com/in/randeeppr
[image: --] Randeep Raman [image: http://]about.me/Randeeppr <http://about.me/Randeeppr> - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
-- Randeep Mob: +919447831699[kerala] Mob: +919880050349[B'lore] http://twitter.com/Randeeppr http://in.linkedin.com/in/randeeppr [image: --] Randeep Raman [image: http://]about.me/Randeeppr <http://about.me/Randeeppr>
Hi, I have modified exec module as: exec get_streaming_data_usage { wait = yes program = "/bin/bash /scripts/get_streaming_data_usage.sh %{Framed-IP-Address}" input_pairs = request output_pairs = reply shell_escape = yes output = none } I have modified my script as follows: [root@freeradius raddb]# cat /scripts/get_streaming_data_usage.sh #/bin/bash #get the framed IP_address: framed_ip_address = $1 #Get the usage in bytes: data_usage = `grep "$framed_ip_address" /scripts/user-bandwidth.txt | cut -d , -f 4` echo Tmp-Integer-2 = $data_usage And in my sites-enabled/default, I'm doing the following comparison. get_streaming_data_usage *#line number 617* Tmp-Integer-3 := `%{expr: "%{control:Tmp-Integer-0}" - "&reply:Tmp-Integer-2"}` where, Tmp-Integer-0 := "%{sql:SELECT (SUM(acctinputoctets)+SUM(acctoutputoctets)) AS Total FROM radacct where radacct.username='%{User-Name}'}" #Value of Max-Data from the radgroupcheck for the group of the user Tmp-Integer-1 := "%{sql: SELECT radgroupcheck.value FROM radusergroup INNER JOIN radgroupcheck ON radusergroup.groupname = radgroupcheck.groupname WHERE radusergroup.username='%{User-Name}' AND radgroupcheck.attribute='Max-Data'}" I'm getting the following error. Thu Oct 22 17:16:34 2015 : Error: /usr/local/etc/raddb/sites-enabled/default*[617]: Missing attribute value* Thu Oct 22 17:16:34 2015 : Error: /usr/local/etc/raddb/sites-enabled/default[569]: Errors parsing accounting section. Do I have to define this variable anywhere? Regards, Randeep On Thu, Oct 22, 2015 at 3:47 PM, Randeep <randeep123@gmail.com> wrote:
No. I'm new to this. Reading it.
Thanks.
On Thu, Oct 22, 2015 at 3:38 PM, Fajar A. Nugraha <list@fajar.net> wrote:
Then on your script, simply echo Attribute-Name = Some-Value
The config SHOULD then be able to use &<list>:Attribute-Name where "list" is "reply".
You DO know about unlang, don't you? http://freeradius.org/radiusd/man/unlang.html
Look for "ATTRIBUTE REFERENCES".
On Thu, Oct 22, 2015 at 5:00 PM, Randeep <randeep123@gmail.com> wrote:
No fajar.
I have wrote a comparison in default file.
I wrote this script only to get a value from a file which will be created by Mikrotik nas.
After reading this value and doing the comparison, function in the default file will send a coa update to apply FUP.
Regards, Randeep
On Thu, Oct 22, 2015 at 3:26 PM, Fajar A. Nugraha <list@fajar.net> wrote:
On Thu, Oct 22, 2015 at 4:52 PM, Randeep <randeep123@gmail.com> wrote:
Yes I did.
echo "Reply-Message += \"Hello, %u\"," echo "Reply-Message += \"PATH=$PATH\"," echo Framed-IP-Address = 255.255.255.255 exit 0
I'm not getting it.
Those are attributes that would go to reply (i.e. sent from radius to the NAS). Remeber "output_pairs = reply"?
If by "apply FUP" you mean "have X attribute in reply items with value Y", then simply
echo X = Y
If you DON'T want to apply FUP, you don't echo that. It should be that simple.
-- Fajar - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
-- Randeep Mob: +919447831699[kerala] Mob: +919880050349[B'lore] http://twitter.com/Randeeppr http://in.linkedin.com/in/randeeppr
[image: --] Randeep Raman [image: http://]about.me/Randeeppr <http://about.me/Randeeppr> - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
-- Randeep Mob: +919447831699[kerala] Mob: +919880050349[B'lore] http://twitter.com/Randeeppr http://in.linkedin.com/in/randeeppr
[image: --] Randeep Raman [image: http://]about.me/Randeeppr <http://about.me/Randeeppr>
-- Randeep Mob: +919447831699[kerala] Mob: +919880050349[B'lore] http://twitter.com/Randeeppr http://in.linkedin.com/in/randeeppr [image: --] Randeep Raman [image: http://]about.me/Randeeppr <http://about.me/Randeeppr>
participants (2)
-
Fajar A. Nugraha -
Randeep