I am trying to run a python file from the telnet session
Steps:
Dailyscript.py
Telnetting in to montavista
from the telnet session I am trying to run another python file "python sample.py"
sample.py
Importing TestLib (in this file)
But, when I run directly form my linux box, it is running fine.
Is there any thing I need?
Most likely the problem is that TestLib.py isn't in your working directory. Make sure your Dailyscript.py sets its directory to wherever you ran it from (over SSH) before executing python sample.py.
Also, if you have SSH access, why aren't you just using SSH?
Related
I have an Azure VM into which I SSH in. The VM is a W10 host.
I can create files with touch, change directories and so on, but whenever I try to run a python script that is hosted on the VM I get the following error:
The system cannot execute the specified program.
At first glance I thought that there was a problem related to my pyhton alias and the PATH variable, so I decided to use RDP to log into the machine, open a CMD and try the same command, which worked just fine. The python program executed flawlessly.
I used where to find where is my python.exe located at, so whenever I run the script on my remote terminal I can do something like:
C:\Users\User01\AppData\Local\Microsoft\WindowsApps\python.exe test.py
This does result in the same error message as the one stated above.
Can I get some help?
Hi try to execute your command as below.
ssh user#machine python < script.py
I would like to execute a python script stored on a remote server on a local machine. This is so I can keep the code for the script on the server without the user having a copy. Is this possible using python?
I am basically trying to secure the code, possibly behind a username and/or password so that way I can easily update the codebase. (Much like using ssh - but the python script is executed on the local machine instead of the server.)
Edit:
Using curl and process substitution this may be achievable:
execute bash script from URL
so that to execute the python script the command is:
python <(curl "http://example.com/test.py" -s -N)
curl also supports password protection which is ideal.
When I execute the script the root path for the script is /dev/fd. When I navigate to this directory and list directory only contains numbers.
Using the above command as an example, is the script downloaded? (and where to). I notice that if I execute the script in a directory such as Desktop it is not downloaded to that location (the working directory).
You can compile the Python code into compiled Python .pyc files and distribute these files, though the local machine should have the same Python environment as the server.
However it is also not impossible for this code to be decompiled.
https://python-compiler.com/post/how-to-distribute-python-program
I am connecting to a remote server through
ssh user#server.com
and run
python script.py
in the appropriate directory. However, I get the error
ImportError: No module named numpy
even though I know the module is installed and the script runs with no problems when I am physically logged in to that server.
None of the answers I was able to find worked (for example this, and this). Do have any ideas as to how I can run the script using ssh?
The remote server has Python 2.6.6 installed, and
which python
returns
/usr/bin/python
The remote serves runs CentOS.
See similar problem describe here: Why does an SSH remote command get fewer environment variables then when run manually?.
Compare your environment variables in the local (physical) mode to the remote mode by running env in both cases. Move missing variables from your local profile to /etc/profile. Then log out from ssh session and connect again.
Another approach: If you don't want to change anything, then after ssh switch to your user via su - <your user>. This may look weird because you already logged it with this user. The difference is, that after su all your env. variables will set like in a local (physical) mode. Advantage: it is quick. Disadvantage: You will have to do it each time you want to run your Python script. So the first approach with configuring /etc/profile may be better on the long run.
I have installed Tomcat in my system and when I type "http://localhost:8081/"
I get the following screen
However when I try to run a .py file from Tomcat, it is unable to interpret the file and shows me the following screen. What should I do to resolve this issue?
Tomcat doesn't know how to run Python scripts without additional configuration. You need to configure Tomcat's CGIServlet in order to run Python scripts.
I have a internal scheduler tool which runs a python script on a remote server. I am using configparser module within my script. When I run this script through the tool it gives me below error.
ImportError: No module named configparser
I don't have access to that remote server so I can't just login to server and install required module.
Is there any way through which I can install configparser module by running any installation script on remote server through the tool ( I can neither download package on remote server nor run any commands, All I can do is, running scripts through this tool.) Please let me know if you need more clarification on this.
How about you do something like this. Create a python script that calls a bash script to do what you want:
install.py:
import subprocess
script = """
source /path/to/venv/bin/activate
pip install AnyPackage
"""
subprocess.call(['sh', '-c', script])
I am assuming you are using a virtualenv. If not, I assume the account that the script-runner uses has sudo access.