Hi Greg
I tried as suggested, but it didn't work :(
root@OpenWrt:~# which python
/usr/bin/python
root@OpenWrt:~#
root@OpenWrt:~# ls -l /usr/bin/python
lrwxrwxrwx 1 root root 23 Feb 14 2018 /usr/bin/python ->
/mnt/usb/usr/bin/python
root@OpenWrt:~# cat /usr/libexec/rpcd/foo
#!/bin/sh
#!/usr/bin/python
. /usr/share/libubox/jshn.sh
case "$1" in
list)
echo '{ "bar": { "arg1": true, "arg2": 32, "arg3": "str" },
"toto": { } }'
;;
call)
case "$2" in
bar)
# read the arguments
read input;
# optionally log the call
logger -t "foo" "call" "$2" "$input"
*/usr/bin/python /root/hello.py*
# return json object or an array
echo '{ "hello": "world" }'
;;
toto)
# return json object or an array
echo '[ "item1", "item2", "item3" ]'
;;
esac
;;
esac
root@OpenWrt:~#
On Thu, Feb 15, 2018 at 12:27 AM, Greg Oliver <[email protected]> wrote:
> On Wed, Feb 14, 2018 at 3:27 PM, Phani Siriki <[email protected]>
> wrote:
>
>> Hi Saverio
>>
>> I tried as suggested. It didn't work :(
>>
>> Best Regards
>> Phani
>>
>> On Wed, Feb 14, 2018 at 2:43 PM, Saverio Proto <[email protected]>
>> wrote:
>>
>>> Add something like:
>>>
>>> #!/usr/bin/env python
>>>
>>> at the first line of your python script
>>>
>>> bash script has #!/bin/sh, so it is correctly detected it is shell script
>>> but for the python code you did not specify any shebang
>>>
>>> Saverio
>>>
>>> 2018-02-14 19:11 GMT+01:00 Phani Siriki <[email protected]>:
>>> > Hi All
>>> >
>>> > I want to execute my custom python scripts in rpc shell script.
>>> However,
>>> > they are not executed. Could someone help me on this?
>>> >
>>> > Example Python script:
>>> > ===================
>>> > root@OpenWrt:~# cat hello.py
>>> > from subprocess import call
>>> >
>>> > call(["touch", "/root/ap1", "down"])
>>> >
>>> > print "{'status':'True'}"
>>> >
>>> > Shell script:
>>> > ==========
>>> > root@OpenWrt:~# cat /usr/libexec/rpcd/foo
>>> > #!/bin/sh
>>> > . /usr/share/libubox/jshn.sh
>>> > case "$1" in
>>> > list)
>>> > echo '{ "bar": { "arg1": true, "arg2": 32, "arg3":
>>> "str" },
>>> > "toto": { } }'
>>> > ;;
>>> > call)
>>> > case "$2" in
>>> > bar)
>>> > # read the arguments
>>> > read input;
>>> >
>>> > # optionally log the call
>>> > logger -t "foo" "call" "$2" "$input"
>>> >
>>> > python /root/hello.py
>>> >
>>> > # return json object or an array
>>> > echo '{ "hello": "world" }'
>>> > ;;
>>> > toto)
>>> > # return json object or an array
>>> > echo '[ "item1", "item2", "item3" ]'
>>> > ;;
>>> > esac
>>> > ;;
>>> > esac
>>> > root@OpenWrt:~#
>>> > root@OpenWrt:~# ubus call -S foo bar '{"arg1": true }'
>>> > {"hello":"world"}
>>> > root@OpenWrt:~#
>>> > root@OpenWrt:~# ls ==========> Files are not created.
>>> > Math foo hello.py
>>> > root@OpenWrt:~#
>>> >
>>> > Best Regards
>>> > Phani
>>>
>>
> It will probably work if you specify the full path to the python
> interpreter (which python) in your script...
>
> _______________________________________________
> openwrt-users mailing list
> [email protected]
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
>
>
_______________________________________________
openwrt-users mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users