I was wondering if it is possible to execute the following :
My Script in UNIX server \HOME\Script folder(File Name:MyScript.py ) . Currently I login to SSH Secure shell client on my windows desktop to access this server and the manually run this script .
MyScript.py
Is there any way , I can run the script remotely from my windows desktop , without needing to login to the SSH Secure sheel client each time .
Yes, there are many ways you accomplish this... if you want to mimic the ssh login and execute the script, you can use pexpect.
Related
I need to create a terminal/console program on my server compute and I want to connect to it with ssh from client. And I want to do it from a python script. So, I figured that I need to somehow have this script run the program (subprocess maybe?) and put it out on the socket.
How can I put out a certain program on a specified socket for ssh connection?
Can I even ssh to a certain program run in a console, not to a whole PC? I need client to have only acces to what I set up.
How can I put out a certain program on a specified socket for ssh connection?
I think that what you actually want to do is changing what is run when logging in with ssh.
You can do this in /etc/passwd by changing /bin/bash to the program you want to run when you log in. Do this for the user that you want to log in to via ssh.
I didn't understand if you wanted to log in from a python script or log in to a python program in an interactive shell, so:
You can use the paramiko library to log into a machine with ssh. (if that is what you want)
I need to create a terminal/console program on my server compute and I want to connect to it with ssh from client.
You can look at this project https://github.com/python-cmd2/cmd2 to build interactive console programs in python.
So I'm currently working on a load balancing python script. In this script I will need to update a file on a server. My plan is to have my python script call a bash script.
In that bash script I'd like to ssh into the server, execute an awk command on a file, then logout.
I can currently ssh into this server manually, because I've set up an ssh key (using Google Cloud Platform). But when I try to run a bash script that only executes
'ssh username#externalIP'
I get the error: Permission denied (publickey)
What am I missing here?
Why not use paramiko to connect via SSH? You can specify a key, as shown in this gist.
By using this, you can easily set which commands to execute on the server.
Probably your private key is in your home directory and python is spawning the bash process as a limited user, try changing your script to include the private key explicitly, if still doesn't work you will have to copy the key and change its permission
To explicitly add the private key:
ssh -i /path/to/private/key user#host
I have made a connection between my openssh client and server. Both sides are window machine. I fail to do the followings:
Enter the python command line interface on my SSH client side, which can be done by entering "python" directly through a command line.
I want to run a python script on a server side by calling it on my client side. This script calls a commercial library to download data from a commercial database.
I can do both perfectly through remote desktop on the server side, but when I use openssh to connect, all fail. Any way to solve, especially item (2)?
If Python is installed on the remote server as C:\Python27 and the script is C:\Foo\bar.py, then get PuTTY. It contains the program plink.exe which can execute remote commands.
The command for you should be
plink.exe user#remote C:\Python27\python C:\Foo\bar.py
as explained in http://the.earth.li/~sgtatham/putty/0.64/htmldoc/Chapter7.html#plink-usage
I am looking for a way to open command prompt of remote PC by using Python. In this process I came only upto open a command prompt from Python and other code is connecting to a windows remote PC but how to combine these two and opening the command prompt of remote PC ?
Simply, I want to send some arguments/commands to remote PC command prompt.
Thank you.
First you need to install SSH on the remote PC's. You test the connection and make sure you are able to login. Google can help if you've not setup ssh before.
Then you can create a python script locally to execute commands over the ssh connection.
You'll probably want to look at either
Fabric -> http://docs.fabfile.org/en/1.8/
or
Paramiko -> http://www.paramiko.org/
Which will be able to run your commands.
I have a simple python script on a Raspberry Pi connected using WiFi that activates an LED. Simple enough.
Is it possible to launch that python script from another device attached to the same network using a simple button in VB.net? Thanks in advance for your help!
You will need to use system call in VB, which run the following command in your PC:
ssh user#rpi:/path/to/command.py arg1 arg2
see this, How do I call a Windows shell command using VB6?.
You will need to run ssh server on the rpi, and possibly set passwordless ssh access using keys.
For ssh on windows, you need either cygwin or putty.