[OpenWrt-Devel] How to execute python script in rpc shell script

Phani Siriki yvsg.phanis at gmail.com
Wed Feb 14 14:07:06 EST 2018


 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 at OpenWrt:~# cat hello.py
from subprocess import call

call(["touch", "/root/ap1", "down"])

print "{'status':'True'}"

*Shell script:*
*==========*
root at 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 at OpenWrt:~#
root at OpenWrt:~# ubus call -S foo bar '{"arg1": true }'
{"hello":"world"}
root at OpenWrt:~#
root at OpenWrt:~# ls              ==========> Files are not created.
Math      foo       hello.py
root at OpenWrt:~#

Best Regards
Phani
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20180214/49cd5faa/attachment.htm>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list