473,657 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3943
John Salerno <jo******@NOSPA Mgmail.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.ma nwrote in message
news:86******** *************** *******@cablesp eedwa.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******@NOSPA Mgmail.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...@gmail NOSPAM.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
3510
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 local computer, how do I do it in python on the Unix side? I don't want to use mount since I don't have permission. Thanks
121
10025
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 support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
4
1870
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 functionality included with it. are there any libraries that I could use? I dont know if i wrote it understandably but maybe picture will explain it:
4
6469
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 define the servername / hostname in my Perl Progrem.. Here is the code:
21
34385
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 obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
0
1809
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 to get the mac address which i can get by connecting to the remote machine and by executing ifconfig command. Now to connect to a remote machine in python i tried using pexpect module by which i can ssh to remote machine and get the mac...
4
3374
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 which seems to be more more mature and usable. From my perspective, the relative immaturity of setuptools and its simultaneous widespread use is a clear python weakness and can make python less easy to absorb than it should be. A few...
4
7257
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 feasible and the best way to achieve this. Thanks, SPJ
2
4315
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 get a comma-seperated information from the table LOCK TABLES foo READ; SELECT a,b,a+b INTO OUTFILE '/tmp/result.txt'
1
8522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8622
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.