Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hi Lars Thank you for your clear explanation. After sourcing the profile file, I am able to execute the python script without any issues. Best Regards Phani On Fri, Apr 6, 2018 at 10:30 PM, Lars Kruse wrote: > Hello Phani, > > > thanks to Damiano's summary of proper usage of the external installation root, > it should now be a solvable riddle ... > > > Am Fri, 6 Apr 2018 20:25:08 -0500 > schrieb Phani Siriki : > >> [..] >> json_get_var $interface "interface" >> json_get_var $tx_power "tx_power" >> >> /usr/bin/python >> /root/change_wifi_tx_power.py $interface $tx_power > /root/file 2>&1 > > You need to make sure, that the environment of this python process contains > the > environment variables, that Damiano mentioned (specifically LD_LIBRARY_PATH). > Thus you need to source the /etc/profile file before the python-call above. > > For your understanding: every process receives an "environment" (set of > textual variables with values) from its parent when it is started. > In your case, then shell script "foo" creates the python process. Thus the > shell script needs to prepare the environment, that the python process should > use. The set of variables that should be inherited by the child process, can > be > configured via "export" (in a shell). > Thus it is not relevant, how your shell is configured, when you are > interacting > with the script via ubus calls (e.g. "ubus call foo ..."). The only relevant > environment is the one, that is passed from the "foo" shell script to the > python process. > > Cheers, > Lars > ___ > openwrt-users mailing list > openwrt-users@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hello Phani, thanks to Damiano's summary of proper usage of the external installation root, it should now be a solvable riddle ... Am Fri, 6 Apr 2018 20:25:08 -0500 schrieb Phani Siriki : > [..] > json_get_var $interface "interface" > json_get_var $tx_power "tx_power" > > /usr/bin/python > /root/change_wifi_tx_power.py $interface $tx_power > /root/file 2>&1 You need to make sure, that the environment of this python process contains the environment variables, that Damiano mentioned (specifically LD_LIBRARY_PATH). Thus you need to source the /etc/profile file before the python-call above. For your understanding: every process receives an "environment" (set of textual variables with values) from its parent when it is started. In your case, then shell script "foo" creates the python process. Thus the shell script needs to prepare the environment, that the python process should use. The set of variables that should be inherited by the child process, can be configured via "export" (in a shell). Thus it is not relevant, how your shell is configured, when you are interacting with the script via ubus calls (e.g. "ubus call foo ..."). The only relevant environment is the one, that is passed from the "foo" shell script to the python process. Cheers, Lars ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hi DV Please find the details below. I am trying to change tx power of wireless interface using netlink sockets. I am using libnl python library to achieve this. Please find the script attached. When this python program is executed in ash shell (My Openwrt has this shell) it works fine. root@OpenWrt:~# iwinfo wlan0 ESSID: unknown Access Point: 00:00:00:00:00:00 Mode: Mesh Point Channel: 11 (2.462 GHz) Tx-Power: 10 dBm Link Quality: unknown/70 Signal: unknown Noise: -95 dBm Bit Rate: unknown Encryption: unknown Type: nl80211 HW Mode(s): 802.11bgn Hardware: unknown [Generic MAC80211] TX power offset: unknown Frequency offset: unknown Supports VAPs: yes PHY name: phy0 root@OpenWrt:~# python change_wifi_tx_power.py wlan0 5 Tx Power 5 Sent 44 bytes to the kernel. root@OpenWrt:~# iwinfo wlan0 ESSID: unknown Access Point: 00:00:00:00:00:00 Mode: Mesh Point Channel: 11 (2.462 GHz) Tx-Power: 5 dBm Link Quality: unknown/70 Signal: unknown Noise: -95 dBm Bit Rate: unknown Encryption: unknown Type: nl80211 HW Mode(s): 802.11bgn Hardware: unknown [Generic MAC80211] TX power offset: unknown Frequency offset: unknown Supports VAPs: yes PHY name: phy0 I am trying to change the tx power parameter without login to the router. So, I thought of using ubus over http to configure the parameter. So, inorder to execue my python code, I wrote a rpc shell script ( foo ) and made it available via ubus. 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": {"arg1": true }, "tx_power": {"interface":"value", "tx_power":10} }' ;; call) case "$2" in bar) # read the arguments read input; json_load "$input" # optionally log the call logger -t "foo" "call" "$2" "$input" # return json object or an array echo '{ "hello": "aaa" }' ;; toto) # return json object or an array echo '[ "item1", "item2", "item3" ]' ;; tx_power) # read the arguments read input; json_load "$input" json_get_var $interface "interface" json_get_var $tx_power "tx_power" /usr/bin/python /root/change_wifi_tx_power.py $interface $tx_power > /root/file 2>&1 echo '{ "hello": "yyy" }' ;; esac ;; esac root@OpenWrt:~# root@OpenWrt:~# ubus list -v | grep -A3 foo 'foo' @d222a4a9 "bar":{"arg1":"Boolean","arg2":"Integer","arg3":"String"} "toto":{"arg1":"Boolean"} "tx_power":{"interface":"String","tx_power":"Integer"} When I tried to change the parameter using ubus, I am seeing the import errors. root@OpenWrt:~# ubus call foo tx_power '{"interface":"wlan0", "tx_power":10}' { "hello": "yyy" } Error file: === root@OpenWrt:~# cat file Traceback (most recent call last): File "/root/change_wifi_tx_power.py", line 41, in from libnl.attr import nla_data, nla_get_string, nla_get_u32, nla_parse, nla_put_u32, nla_get_u64 File "/mnt/usb/usr/lib/python2.7/site-packages/libnl/attr.py", line 15, in from libnl.linux_private.netlink import NLA_ALIGN, NLA_F_NESTED, NLA_HDRLEN, NLA_TYPE_MASK, nlattr, NLMSG_ALIGN File "/mnt/usb/usr/lib/python2.7/site-packages/libnl/linux_private/netlink.py", line 10, in from libnl.misc import (bytearray_ptr, c_int, c_uint, c_uint16, c_uint32, c_ushort, SIZEOF_INT, SIZEOF_U16, SIZEOF_U32, File "/mnt/usb/usr/lib/python2.7/site-packages/libnl/misc.py", line 3, in import ctypes File "/mnt/usb/usr/lib/python2.7/ctypes/__init__.py", line 10, in from _ctypes import Union, Structure, Array ImportError: File not found root@OpenWrt:~# root@OpenWrt:~# df -h FilesystemSize Used Available Use% Mounted on rootfs4.5M332.0K 4.2M 7% / /dev/root 2.3M 2.3M 0 100% /rom tmpfs61.6M 64.0K 61.5M 0% /tmp /dev/mtdblock34.5M332.0K 4.2M 7% /overlay overlayfs:/overlay4.5M332.0K 4.2M 7% / tmpfs 512
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Il 7 aprile 2018 01:38:34 CEST, Phani Siriki ha scritto: >... >I am unable to import the ctypes library while executing python script >in rpc shell script. Please, provide details: cut&paste of terminal session, detailed command launched and error messages, screenshot, ...whatever. Without details, I can't get a clear figure of your scenario. >When I run the same script in bash it works fine. Are you sure it's a full BASH Shell? >Even without three >symbolic links. > I have created all the env variables and sourced >profile before running the script. Again: details regarding the script! Bye, DV -- Sent via my new (unlocked) Xiaomi Redmi Note 4 ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hi DV Thank you for your inputs. I am unable to import the ctypes library while executing python script in rpc shell script. When I run the same script in bash it works fine. ( Even without three symbolic links.) I have created all the env variables and sourced profile before running the script. Best Regards Phani On Fri, Apr 6, 2018 at 5:20 PM, Damiano Verzulli wrote: > On 06/04/2018 23:20, Lars Kruse wrote: >>| [...] >>> I am able to execute python script after creating below soft links. >>> >>> ln -s /mnt/usb/usr/lib/libz.so.1 /usr/lib/libz.so.1 >>> ln -s /mnt/usb/lib/libpthread.so.0 /usr/lib/libpthread.so.0 >>> ln -s /mnt/usb/usr/lib/libpython2.7.so.1.0 /usr/lib/libpython2.7.so.1.0 >> >> The fact that you need to create symlinks manually feels wrong to me. >> >> I am not used to installing packages to non-root locations, thus I cannot >> tell, >> whether this is normal or an indication of a problem. Can you tell? > > > I guess that the three symbolic links above are required 'cause: > > - some packages have been installed inside the USB storage (/mnt/usb) and, > as such, some important libraries (libz.so.1, libpthread.so.0, > libpython2.7.so.1.0) are stored under such folder; > > - some other application (Python 2.7, I guess) is "dinamically lynked" to > such libraries. This means that to succesfully run python 2.7, those > libraries needs to be "retrieved and read" (as they are part of python > itself!). If they are NOT found, the application (python 2.7) cannot start; > > - the set of folder used by Linux (and OpenWRT) to search for dynamic > libraries is quite fixed and, by default: > - does _NOT_ include /mnt/usr/lib nor /mnt/usb/usr/lib > - _DOES_ include /usr/lib > > So, by defining above symbolic links, Phani is simply offering to OpenWRT a > chance to find the dinamic libraries in "default folder" (/usr/lib) even if > they are really stored inside /mnt/usb/usr/lib. > > > Anyway, the proper way to solve such a problem is a bit different. > > As mentioned in the guide pointed by Phani in his last message: > > http://nixorids.blogspot.com/2013/03/installing-packages-into-usb-on-tl.html > > some environment variable should be "updated" (when relying on USB > storage). In detail: > > export USB=/mnt/usb > export PATH=$PATH:$USB/usr/bin:$USB/usr/sbin # This PATH is dependent on > existing $PATH > export LD_LIBRARY_PATH=$USB/lib:$USB/usr/lib > > - The first one simply define the mount-point of the USB storage; > > - The second one simply tell that binaries stored inside the USB should be > directly accessible, without specifying a full-path; > > - The first, and MOST IMPORTANT, line defines _TWO_ folders (/mnt/usb/lib > AND /mnt/usb/usr/lib) to be used for searching of dynamic libraries, IN > ADDITION to standard ones. > > Actually, the LD_LIBRARY_PATH environment variables has exactly such a > purpose. > > Hence, instead of creating the three symbolic links (and, maybe, missing > several others), it's much better to define such a LD_LIBRARY_PATH. > > It's important to note that such a LD_LIBRARY_PATH should be defined > _BEFORE_ launching the program requiring related libraries. > > > Exactly for this reason, the same already mentioned guide refers the > /etc/profile file (where the three environment variables should be defined) > and the command: > > # source /etc/profile > > that, when launched, "import" such variables inside the current environment. > > > > So, in the end: > > 1 - remove the symbolic links; > 2 - create the /etc/profile taking care to define the three variables; > 3 - before launching "python", ensure to "source /etc/profile" [it's > required only once] > > In this way, not only the three libraries above, but also any other library > stored inside /mnt/usb should be accessible with not problem. > > Hope this help! > > Cheers, > DV > > -- > Damiano Verzulli > e-mail: dami...@verzulli.it > --- > possible?ok:while(!possible){open_mindedness++} > --- > "Technical people tend to fall into two categories: Specialists > and Generalists. The Specialist learns more and more about a > narrower and narrower field, until he eventually, in the limit, > knows everything about nothing. The Generalist learns less and > less about a wider and wider field, until eventually he knows > nothing about everything." - William Stucke - AfrISPA > http://elists.isoc.org/mailman/private/pubsoft/2007-December/001935.html > > > ___ > openwrt-users mailing list > openwrt-users@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users > ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
On 06/04/2018 23:20, Lars Kruse wrote: >| [...] >> I am able to execute python script after creating below soft links. >> >> ln -s /mnt/usb/usr/lib/libz.so.1 /usr/lib/libz.so.1 >> ln -s /mnt/usb/lib/libpthread.so.0 /usr/lib/libpthread.so.0 >> ln -s /mnt/usb/usr/lib/libpython2.7.so.1.0 /usr/lib/libpython2.7.so.1.0 > > The fact that you need to create symlinks manually feels wrong to me. > > I am not used to installing packages to non-root locations, thus I cannot > tell, > whether this is normal or an indication of a problem. Can you tell? I guess that the three symbolic links above are required 'cause: - some packages have been installed inside the USB storage (/mnt/usb) and, as such, some important libraries (libz.so.1, libpthread.so.0, libpython2.7.so.1.0) are stored under such folder; - some other application (Python 2.7, I guess) is "dinamically lynked" to such libraries. This means that to succesfully run python 2.7, those libraries needs to be "retrieved and read" (as they are part of python itself!). If they are NOT found, the application (python 2.7) cannot start; - the set of folder used by Linux (and OpenWRT) to search for dynamic libraries is quite fixed and, by default: - does _NOT_ include /mnt/usr/lib nor /mnt/usb/usr/lib - _DOES_ include /usr/lib So, by defining above symbolic links, Phani is simply offering to OpenWRT a chance to find the dinamic libraries in "default folder" (/usr/lib) even if they are really stored inside /mnt/usb/usr/lib. Anyway, the proper way to solve such a problem is a bit different. As mentioned in the guide pointed by Phani in his last message: http://nixorids.blogspot.com/2013/03/installing-packages-into-usb-on-tl.html some environment variable should be "updated" (when relying on USB storage). In detail: export USB=/mnt/usb export PATH=$PATH:$USB/usr/bin:$USB/usr/sbin # This PATH is dependent on existing $PATH export LD_LIBRARY_PATH=$USB/lib:$USB/usr/lib - The first one simply define the mount-point of the USB storage; - The second one simply tell that binaries stored inside the USB should be directly accessible, without specifying a full-path; - The first, and MOST IMPORTANT, line defines _TWO_ folders (/mnt/usb/lib AND /mnt/usb/usr/lib) to be used for searching of dynamic libraries, IN ADDITION to standard ones. Actually, the LD_LIBRARY_PATH environment variables has exactly such a purpose. Hence, instead of creating the three symbolic links (and, maybe, missing several others), it's much better to define such a LD_LIBRARY_PATH. It's important to note that such a LD_LIBRARY_PATH should be defined _BEFORE_ launching the program requiring related libraries. Exactly for this reason, the same already mentioned guide refers the /etc/profile file (where the three environment variables should be defined) and the command: # source /etc/profile that, when launched, "import" such variables inside the current environment. So, in the end: 1 - remove the symbolic links; 2 - create the /etc/profile taking care to define the three variables; 3 - before launching "python", ensure to "source /etc/profile" [it's required only once] In this way, not only the three libraries above, but also any other library stored inside /mnt/usb should be accessible with not problem. Hope this help! Cheers, DV -- Damiano Verzulli e-mail: dami...@verzulli.it --- possible?ok:while(!possible){open_mindedness++} --- "Technical people tend to fall into two categories: Specialists and Generalists. The Specialist learns more and more about a narrower and narrower field, until he eventually, in the limit, knows everything about nothing. The Generalist learns less and less about a wider and wider field, until eventually he knows nothing about everything." - William Stucke - AfrISPA http://elists.isoc.org/mailman/private/pubsoft/2007-December/001935.html signature.asc Description: OpenPGP digital signature ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hi Lars I have followed below site to install packages on USB. http://nixorids.blogspot.com/2013/03/installing-packages-into-usb-on-tl.html Packages installed in USB are working fine. However, when I am executing python script in a ubus shell script, it is not working :( Best Regards Phani On Fri, Apr 6, 2018 at 4:20 PM, Lars Kruse wrote: > Hello Phani, > > > let us step back to this issue ... > > > Am Wed, 4 Apr 2018 15:02:13 -0500 > schrieb Phani Siriki : > >> I am able to execute python script after creating below soft links. >> >> ln -s /mnt/usb/usr/lib/libz.so.1 /usr/lib/libz.so.1 >> ln -s /mnt/usb/lib/libpthread.so.0 /usr/lib/libpthread.so.0 >> ln -s /mnt/usb/usr/lib/libpython2.7.so.1.0 /usr/lib/libpython2.7.so.1.0 > > The fact that you need to create symlinks manually feels wrong to me. > > I am not used to installing packages to non-root locations, thus I cannot > tell, > whether this is normal or an indication of a problem. Can you tell? > > I would recommend to verify, that your setup in general is correctly > configured. > Did you follow a reasonable documentation? Which one? > Did you deviate? Did you notice problems, that you had to work around? > > Maybe someone else has an idea what is going wrong here? > > Cheers, > Lars > ___ > openwrt-users mailing list > openwrt-users@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hello Phani, let us step back to this issue ... Am Wed, 4 Apr 2018 15:02:13 -0500 schrieb Phani Siriki : > I am able to execute python script after creating below soft links. > > ln -s /mnt/usb/usr/lib/libz.so.1 /usr/lib/libz.so.1 > ln -s /mnt/usb/lib/libpthread.so.0 /usr/lib/libpthread.so.0 > ln -s /mnt/usb/usr/lib/libpython2.7.so.1.0 /usr/lib/libpython2.7.so.1.0 The fact that you need to create symlinks manually feels wrong to me. I am not used to installing packages to non-root locations, thus I cannot tell, whether this is normal or an indication of a problem. Can you tell? I would recommend to verify, that your setup in general is correctly configured. Did you follow a reasonable documentation? Which one? Did you deviate? Did you notice problems, that you had to work around? Maybe someone else has an idea what is going wrong here? Cheers, Lars ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hi Lars Thanks for your input. The path is same for both conditions. But I cannot import ctypes while executing through ubus. Execute shell script: === root@OpenWrt:~# sh foo call tx_power { "hello": "yyy" } root@OpenWrt:~# root@OpenWrt:~# root@OpenWrt:~# root@OpenWrt:~# cat /tmp/pythonpath.out /root /mnt/usb/usr/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg /mnt/usb/usr/lib/python27.zip /mnt/usb/usr/lib/python2.7 /mnt/usb/usr/lib/python2.7/plat-linux2 /mnt/usb/usr/lib/python2.7/lib-tk /mnt/usb/usr/lib/python2.7/lib-old /mnt/usb/usr/lib/python2.7/lib-dynload /mnt/usb/usr/lib/python2.7/site-packages /mnt/usb/usr/lib/python2.7/site-packages/setuptools-7.0-py2.7.eggroot@OpenWrt:~# root@OpenWrt:~# Execute shell script via ubus: = root@OpenWrt:~# rm /tmp/pythonpath.out root@OpenWrt:~# root@OpenWrt:~# root@OpenWrt:~# ubus call foo tx_power { "hello": "yyy" } root@OpenWrt:~# root@OpenWrt:~# root@OpenWrt:~# cat /tmp/pythonpath.out /root /mnt/usb/usr/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg /mnt/usb/usr/lib/python27.zip /mnt/usb/usr/lib/python2.7 /mnt/usb/usr/lib/python2.7/plat-linux2 /mnt/usb/usr/lib/python2.7/lib-tk /mnt/usb/usr/lib/python2.7/lib-old /mnt/usb/usr/lib/python2.7/lib-dynload /mnt/usb/usr/lib/python2.7/site-packages /mnt/usb/usr/lib/python2.7/site-packages/setuptools-7.0-py2.7.eggroot@OpenWrt:~# root@OpenWrt:~# Best Regards Phani On Thu, Apr 5, 2018 at 9:47 PM, Lars Kruse wrote: > Hello Phani, > > > Am Wed, 4 Apr 2018 15:02:13 -0500 > schrieb Phani Siriki : > >> I am able to import the module through normal execution. However it is >> not working in rpcd shell script. Could you please give me some >> inputs? > > you could try to compare the search path under both conditions. > > Probably the following would be sufficient? > > open("/tmp/pythonpath.out", "w").write("\n".join(sys.path)) > > (to be placed before the critical import statement) > > > Cheers, > Lars > ___ > openwrt-users mailing list > openwrt-users@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hello Phani, Am Wed, 4 Apr 2018 15:02:13 -0500 schrieb Phani Siriki : > I am able to import the module through normal execution. However it is > not working in rpcd shell script. Could you please give me some > inputs? you could try to compare the search path under both conditions. Probably the following would be sufficient? open("/tmp/pythonpath.out", "w").write("\n".join(sys.path)) (to be placed before the critical import statement) Cheers, Lars ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hi Lars Thanks for your input. I am able to execute python script after creating below soft links. ln -s /mnt/usb/usr/lib/libz.so.1 /usr/lib/libz.so.1 ln -s /mnt/usb/lib/libpthread.so.0 /usr/lib/libpthread.so.0 ln -s /mnt/usb/usr/lib/libpython2.7.so.1.0 /usr/lib/libpython2.7.so.1.0 However, I am unable to import "ctypes" module. I am getting below error. Traceback (most recent call last): File "/root/change_wifi_params.py", line 43, in import ctypes File "/mnt/usb/usr/lib/python2.7/ctypes/__init__.py", line 10, in from _ctypes import Union, Structure, Array ImportError: File not found sys.path: === /mnt/usb/usr/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg /mnt/usb/usr/lib/python27.zip /mnt/usb/usr/lib/python2.7 /mnt/usb/usr/lib/python2.7/plat-linux2 /mnt/usb/usr/lib/python2.7/lib-tk /mnt/usb/usr/lib/python2.7/lib-old /mnt/usb/usr/lib/python2.7/lib-dynload /mnt/usb/usr/lib/python2.7/site-packages /mnt/usb/usr/lib/python2.7/site-packages/setuptools-7.0-py2.7.egg root@OpenWrt:~# root@OpenWrt:~# ls /mnt/usb/usr/lib/python2.7/lib-dynload/_ctypes.so /mnt/usb/usr/lib/python2.7/lib-dynload/_ctypes.so root@OpenWrt:~# I am able to import the module through normal execution. However it is not working in rpcd shell script. Could you please give me some inputs? root@OpenWrt:~# python Python 2.7.9 (default, Sep 9 2015, 07:59:02) [GCC 4.8.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import ctypes >>> >>> root@OpenWrt:~# Best Regards Phani On Sat, Feb 17, 2018 at 1:16 PM, wrote: > Sure Lars. I will check it. > > Best regards > Phani > > Sent from my iPhone > >> On Feb 17, 2018, at 12:55 PM, Lars Kruse wrote: >> >> Hello Phani, >> >> >> Am Sat, 17 Feb 2018 12:22:02 -0600 >> schrieb Phani Siriki : >> >>> root@OpenWrt:~# cat file-name >>> /usr/bin/python: can't load library 'libpython2.7.so.1.0' >> >> so this discussion revolved around the same topic as your other thread >> ("Pip command found error even though pip is installed"). >> Thus you will need to fix your python installation. >> >> The usual steps: >> * remove and install again >> * find out, how your setup differs from the setup of others >> >> Cheers, >> Lars >> ___ >> openwrt-users mailing list >> openwrt-users@lists.openwrt.org >> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Sure Lars. I will check it. Best regards Phani Sent from my iPhone > On Feb 17, 2018, at 12:55 PM, Lars Kruse wrote: > > Hello Phani, > > > Am Sat, 17 Feb 2018 12:22:02 -0600 > schrieb Phani Siriki : > >> root@OpenWrt:~# cat file-name >> /usr/bin/python: can't load library 'libpython2.7.so.1.0' > > so this discussion revolved around the same topic as your other thread > ("Pip command found error even though pip is installed"). > Thus you will need to fix your python installation. > > The usual steps: > * remove and install again > * find out, how your setup differs from the setup of others > > Cheers, > Lars > ___ > openwrt-users mailing list > openwrt-users@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hello Phani, Am Sat, 17 Feb 2018 12:22:02 -0600 schrieb Phani Siriki : > root@OpenWrt:~# cat file-name > /usr/bin/python: can't load library 'libpython2.7.so.1.0' so this discussion revolved around the same topic as your other thread ("Pip command found error even though pip is installed"). Thus you will need to fix your python installation. The usual steps: * remove and install again * find out, how your setup differs from the setup of others Cheers, Lars ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hi Lars Sorry for the late reply. Thank you for the awesome suggestion. I redirected stderr to file and observed below error. shell script: ... /usr/bin/python /root/hello.py > /root/file-name 2>&1 ... root@OpenWrt:~# cat file-name /usr/bin/python: can't load library 'libpython2.7.so.1.0' root@OpenWrt:~# which python /usr/bin/python root@OpenWrt:~# ls -l /usr/bin/python lrwxrwxrwx1 root root23 Feb 14 2018 /usr/bin/python -> /mnt/usb/usr/bin/python root@OpenWrt:~# ldd python libpython2.7.so.1.0 => /mnt/usb/usr/lib/libpython2.7.so.1.0 (0x77864000) libpthread.so.0 => /mnt/usb/lib/libpthread.so.0 (0x7783e000) libdl.so.0 => /lib/libdl.so.0 (0x7782a000) libutil.so.0 => /lib/libutil.so.0 (0x77819000) libz.so.1 => /mnt/usb/usr/lib/libz.so.1 (0x777fb000) libm.so.0 => /lib/libm.so.0 (0x777d5000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x777b1000) libc.so.0 => /lib/libc.so.0 (0x77744000) ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0x779fa000) Could you please help me how to resolve this? Best Regards Phani On Thu, Feb 15, 2018 at 3:11 PM, Lars Kruse wrote: > Hello Phani, > > > Am Thu, 15 Feb 2018 09:21:09 -0600 > schrieb Phani Siriki : > > > I tried as suggested, but it didn't work :( > > Just in case you are running out of ideas: > did you try the suggestions that I put down in my first response to this > thread > (Wed, 14 Feb 2018 21:56:08 +0100)? > What did you discover along this path? > > Cheers, > Lars > ___ > openwrt-users mailing list > openwrt-users@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users > ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hello Phani, Am Thu, 15 Feb 2018 09:21:09 -0600 schrieb Phani Siriki : > I tried as suggested, but it didn't work :( Just in case you are running out of ideas: did you try the suggestions that I put down in my first response to this thread (Wed, 14 Feb 2018 21:56:08 +0100)? What did you discover along this path? Cheers, Lars ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
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 lrwxrwxrwx1 root root23 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 wrote: > On Wed, Feb 14, 2018 at 3:27 PM, Phani Siriki > 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 >> 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 : >>> > 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 > openwrt-users@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users > > ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
On Wed, Feb 14, 2018 at 3:27 PM, Phani Siriki 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 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 : >> > 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 openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hi Saverio I tried as suggested. It didn't work :( Best Regards Phani On Wed, Feb 14, 2018 at 2:43 PM, Saverio Proto 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 : > > 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 > > > > ___ > > openwrt-users mailing list > > openwrt-users@lists.openwrt.org > > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users > > > ___ > openwrt-users mailing list > openwrt-users@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users > ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hello Saverio, Am Wed, 14 Feb 2018 21:43:46 +0100 schrieb Saverio Proto : > Add something like: > > #!/usr/bin/env python > > at the first line of your python script in this specific case it is not relevant, since he is calling the interpreter with the script filename as an argument ("python /root/hello.py"). But it would be necessary if he just called the script without specifying the interpreter (e.g. "/root/hello.py"). Anyway: a shebang is surely always a good thing for scripts. Cheers, Lars ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
Hello Phani, Am Wed, 14 Feb 2018 12:11:16 -0600 schrieb Phani Siriki : > I want to execute my custom python scripts in rpc shell script. However, > they are not executed. Could someone help me on this? I am not familiar with the details of the rpcd insterface you are using - but probably your problem is generic, anyway. You should probably walk along the usual debugging path: - try to find out, why no messages from stderr are printed (failure to call the python script or failure within the python script) - maybe redirect stderr to stdout in your call of the python interpreter - maybe start the python script with some "print" statements (instead of "call") in order to find out, if the python script is running at all - if everything fails: use strace or similar tools in order to find out, if the python script file is accessed at all - ... Happy hunting! Lars PS: please do not cross post (here: at least openwrt-user and openwrt-devel mailinglists) - see [1] [1] http://catb.org/~esr/faqs/smart-questions.html#forum ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
Re: [OpenWrt-Users] How to execute python script in rpc shell script
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 : > 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 > > ___ > openwrt-users mailing list > openwrt-users@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users > ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users
[OpenWrt-Users] How to execute python script in rpc shell script
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 ___ openwrt-users mailing list openwrt-users@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users