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
Related
I need to setup a Jetson Nano device so that a Python script is launched everytime an Internet connection is available.
So, referring to this question, I did the following:
I created the 'run_when_connection_available' script:
#!/bin/sh
# create a dummy folder to check script execution
mkdir /home /user_name/dummy_folder_00
# kill previous instances of the system
pkill python3
# move to folder with python script and launch it
cd /home/user_name/projects/folder
/usr/bin/python3 launcher.py --arg01 --arg02 ...
# create another dummy folder to check script execution
mkdir /home /user_name/dummy_folder_01
I made this script executable and I copied it to /etc/network/if-up.d
Now, everytime I plug the ethernet cable out and in again, I can see the dummy folders are created in /home/user_name, but the python script isn't launched (at least, it doesn't appear in the system monitor). I tried running the command in the script from the terminal, and everything works fine, the python program starts as expected. Am I doing something wrong?
I'm trying to figure out something similar to you, but not quite the same..
This solution got my script python script running upon internet connection, I can check the logs and everything is working fine:
Raspbian - Running A Script After An Internet Connection Is Established
However, my script uses notify-send to send notifications to my window manager which I can't seem to get working with systemd - the script works when run inside of the user space so I assume it's something to do with systemd and Xorg. Hopefully that shouldn't be a problem for you, I hope this solves your issue.
You shouldn't need a bash script in the middle, I got systemd service to run my python script with chmod u+x <file>.py and putting #!/usr/bin/env python3 at the top of the python file so that it's executable directly under the .service file like so:
ExecStart=/path/to/file/file.py
Ok, I guess it was a matter of permissions, I solved it by running everything as user_name, so I modified the script as
sudo -user user_name /usr/bin/python3 launcher.py --arg01 --arg02 ...
I have a python script that uses Popen to create an appium server for a simulator on a mac
self.appium_process = subprocess.Popen(["/usr/local/bin/appium", "-a", self.ip, "--nodeconfig", self.node_file_path, "--relaxed-security", "-p", str(appium_port), "-dc", default_capabilities], stdout=log_file, stderr=subprocess.STDOUT)
I created a bash shell script that calls the python script. When I run the script from the local box it works and the appium logs show the connection.
I need to run this remote via ssh however. So I use the following to call the script:
ssh 10.18.66.99 automation_fw/config/testscript.sh
This, however, always ends up with the log showing:
env: node: No such file or directory
I checked and the node app has an extra slash before its called:
$ which node
/usr/local/bin//node
$
I tried changing the path on the machine but no change. How can I get this to run from ssh in the same way as it can run locally on that same box
A
When you are running a command vis SSH you are not starting what's called a login shell (more about that here).
From the details you've shared, I would say it's some thing in your environment (running outside a logged-in shell), more specifically a problem with your $PATH variable. You might want to check /etc/environment or similar paths (depending on your Linux flavour) for the wrong value.
I have a remote server and I want to use Pycharm to execute my scripts on this remote server using SFTP and SSH. Everything works properly, except that, when running the scripts on the server through the Pycharm "Run" command, the PATH is wrong. I am trying to understand which file I should edit to properly set the PATH environmental variable. I am using a mac and the server runs ubuntu. After having installed several libraries on the server, I edited the .bashrc file in my home directory on the server to properly set up the PATH. Then the following happens:
If I login to the server using ssh and the mac terminal, the PATH is loaded correctly.
If I open a ssh session inside pycharm and connect to the server, the PATH is loaded correctly.
If I run a simple script (that only contains calls to the standard library) on the remote server through the Pycharm "Run" command, it works
If I run the full script on the remote server through the pycharm "Run" command, then in crashes: os.environ['PATH'] shows that the path is not correct
If I run the script by directly calling the python interpreter on the server using one of the terminal ssh session, then the PATH is set up properly and it works
So apparently the PATH is set up properly if I connect to it using ssh and the terminal, but when Pycharm tries to run it directly the PATH is not updated and it crashes.
So I am guessing pycharm doesn't look into .bashrc before running the program. Which file should I modify then? Note that the only "configuration" files present in my home directory on the remote server are .bashrc and .profile.
Note I do not have sudo privileges on this server.
I'm connected to a Raspberry Pi via ssh. I'm trying to run a script on the RPi but rather than using a nano editor on the terminal I want to execute a python script based on my mac (the server of the SSH).
However when typing
'sudo python /Users/User/Pythonscript.py'
terminal returns
'python: can't open file '/Users/User/Pythonscript.py': [Errno 2] No such file or directory'
And yet this file does exist under that directory.
Any ideas?
Ok, if I have properly understood, you have script on your client and want to execute it on Pi from ssh.
scp /path/to/script.py user#hostname:/path/to/
then add your rsa key to your server. This perfect guide tells you how.
Then just write .sh, which get access to your server ssh user#hostname, then cd /path/to and, finally python script.py
You have a file on your Mac and want to execute it on your Pi. Two things need to be done: First, get the file to the Pi. Second log in to the Pi and run it. Apparently, you managed step two, so I'll address step 1.
The simple solution: scp, e.g. scp /Users/User/Pythonscript.py <user>#<ip_of_pi>:<target_dir>
The solution that might be longer-term more feasible, if you want to develop locally: sshfs. It's available via Homebrew. You mount a directory locally, and anything you change will automatically be reflected on the respective directory on the Pi. Here's a tutorial how to install and use sshfs. On first glance, it seems reasonable.
No matter how you get your script to the Pi, you need to find it on the Pi and execute it there.
I'm writing a program to monitor a python script running. There will be multiple instances of this script, which is a server, running from different locations on the computer. My program will be monitoring to see that all instances that are being "watched" are up and running and will restart them as necessary.
The server script cannot be edited.
My problem is that the server process just shows up as the python executable, and I am unable to determine the location of the specific server script on the computer.
Is there anyway to determine what script is actually running on a specific python/pythonw.exe process? And also its path?
ENV: Windows only
You can run the following command from the command line:
WMIC PROCESS get Caption,Commandline,Processid,ExecutablePath
This will show you which module is being executed.