473,323 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Using Python to run SSH commands on a remote server

Generally speaking, what tools would I use to do this? Is there a built-in
module for it? I looked at the telnetlib module, but the documentation
wasn't really complete enough for me to get a good idea of it. Is Telnet and
SSH even the same thing?

Basically, I want to write a script that will automate the process of making
all .py files on my web server executable (chmod 755, or something similar).

Thanks.
Jun 27 '08 #1
8 3921
John Salerno <jo******@NOSPAMgmail.comwrote:
Generally speaking, what tools would I use to do this? Is there a built-in
module for it?
There's paramiko (q.g.). I can't personally vouch for it, but it seems
popular... It seems to depend on a separate crypto library.
Is Telnet and SSH even the same thing?
No. They're very different.

-- [mdw]
Jun 27 '08 #2
John Salerno wrote:
Generally speaking, what tools would I use to do this? Is there a built-in
module for it?
I've had a very nice experience using the 3rd-party package "paramiko" for
ssh communication. There's nothing in the standard library that I know of.
I looked at the telnetlib module, but the documentation
wasn't really complete enough for me to get a good idea of it. Is Telnet
and SSH even the same thing?
Telnet is not the same protocol. SSH is an encrypted transport, telnet is
not.
Basically, I want to write a script that will automate the process of
making all .py files on my web server executable (chmod 755, or something
similar).
Be careful, this procedure sounds potential risky, security-wise ;-)
Jeffrey
Jun 27 '08 #3
"Jeffrey Froman" <je*****@fro.manwrote in message
news:86******************************@cablespeedwa .com...
Be careful, this procedure sounds potential risky, security-wise ;-)
I guess a blanket process might be a tad risky, but don't you want all CGI
files to be executable by all?
Jun 27 '08 #4
On 2008-06-23, John Salerno <jo******@NOSPAMgmail.comwrote:
Generally speaking, what tools would I use to do this?
In shell scripts I use expect to automate ssh stuff, so I would
probably give pyexpect or pexpect a try:

http://sourceforge.net/projects/pexpect/
Is there a built-in module for it? I looked at the telnetlib
module, but the documentation wasn't really complete enough
for me to get a good idea of it. Is Telnet and SSH even the
same thing?
Not even close.
Basically, I want to write a script that will automate the
process of making all .py files on my web server executable
(chmod 755, or something similar).
I'd probably just write an expect script:

http://expect.nist.gov/

--
Grant Edwards grante Yow! Is a tattoo real, like
at a curb or a battleship?
visi.com Or are we suffering in
Safeway?
Jun 27 '08 #5
John Salerno wrote:
I guess a blanket process might be a tad risky, but don't you want all CGI
files to be executable by all?
Typically, I prefer CGI scripts to be executable only the owner. If the web
server runs those scripts as a different user, then that user must also be
permitted to execute the scripts of course.

Also note that "all .py files on my web server" is not necessarily
restricted to CGI scripts -- and therein lies the real gist of my
cautionary note.
Jeffrey
Jun 27 '08 #6
Jeffrey Froman wrote:
Also note that "all .py files on my web server" is not necessarily
restricted to CGI scripts -- and therein lies the real gist of my
cautionary note.
Yeah, I realized that afterwards. Good point. I was assuming all my
executable files would be CGI, but that's not a good assumption to make! :)
Jun 27 '08 #7
On Jun 24, 3:51 am, John Salerno <johnj...@gmailNOSPAM.comwrote:
Jeffrey Froman wrote:
Also note that "all .py files on my web server" is not necessarily
restricted to CGI scripts -- and therein lies the real gist of my
cautionary note.

Yeah, I realized that afterwards. Good point. I was assuming all my
executable files would be CGI, but that's not a good assumption to make! :)
You can execute ssh using os.system(). Look at
http://love-python.blogspot.com/2008...in-python.html
If you want non-interactive ssh (so that your script doesn't need to
enter password), look at: http://speed-dev.blogspot.com/2008/0...-in-linux.html

regards,
Subeen.
Jun 27 '08 #8
Alson you can take a look at pexpect module if you want to automate
logging in and process commands , in this way you will no longer wait
for loginname and password prompt.
Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Thierry Lam | last post by:
Is it possible to run an ftp command to connect to some remote computer on the network. For example, if I want to retrieve some data from \\remcomputer\datafiles on the network and copy it to my...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
4
by: linuxpld | last post by:
Hello I`m writing a program (server in future) in python. I would like to write it in such a way that I will be able to write gui in any language and connect to my python program and use...
4
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
0
vinoj
by: vinoj | last post by:
Hi All, These are the following things which i want to do:- 1. I will be taking the ipaddress, username and password from the user using cgi ffrom the browser. 2. Now i want...
4
by: Alia Khouri | last post by:
Can we open up the discussion here about how to improve setuptools which has become the de facto standard for distributing / installing python software. I've been playing around with ruby's gems...
4
by: SPJ | last post by:
Is it possible to run specific commands on cisco router using Python? I have to run command "show access-list" on few hundred cisco routers and get the dump into a file. Please let me know if it is...
2
by: Nikhil | last post by:
I am using the MySQLdb python module. I have a table named 'testing' with few columns, under the 'test' database, what is hosted on a remote mysql server. I want to run the following query to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.