Phani Siriki
2018-02-14 19:07:06 UTC
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:*
*===================*
***@OpenWrt:~# cat hello.py
from subprocess import call
call(["touch", "/root/ap1", "down"])
print "{'status':'True'}"
*Shell script:*
*==========*
***@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
***@OpenWrt:~#
***@OpenWrt:~# ubus call -S foo bar '{"arg1": true }'
{"hello":"world"}
***@OpenWrt:~#
***@OpenWrt:~# ls ==========> Files are not created.
Math foo hello.py
***@OpenWrt:~#
Best Regards
Phani
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:*
*===================*
***@OpenWrt:~# cat hello.py
from subprocess import call
call(["touch", "/root/ap1", "down"])
print "{'status':'True'}"
*Shell script:*
*==========*
***@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
***@OpenWrt:~#
***@OpenWrt:~# ubus call -S foo bar '{"arg1": true }'
{"hello":"world"}
***@OpenWrt:~#
***@OpenWrt:~# ls ==========> Files are not created.
Math foo hello.py
***@OpenWrt:~#
Best Regards
Phani