Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8792731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:01:14+00:00 2026-06-13T23:01:14+00:00

I would like to write a script that performs the following Linux commands sequence:

  • 0

I would like to write a script that performs the following Linux commands sequence:

  1. rsh rr01 ( here the system will ask for password )
  2. ssh rr02 ( here the system will ask for password again)
  3. activate my app on some file

I was naively (and stupidly) tried to accomplish that with a simple os.system
bear in mind I using python 2.3 and would like to avoid adding modules (if possible).

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:01:15+00:00Added an answer on June 13, 2026 at 11:01 pm

    [EDIT] Check out also another example using paramiko on http://code.google.com/p/lexel-intern0t/source/browse/trunk/Python/ssh_client.py.

    The script found on http://media.commandline.org.uk//code/ssh.txt may help you. It includes os module (to find the keys) and tempfile module for logging purposes, both found in python 2.3 global module index ( http://docs.python.org/release/2.3/modindex.html ) and paramiko ( http://www.lag.net/paramiko/docs/ ) for the SSH2 protocol implementation, which is supposed to work on python 2.3 and above. It’s a simple piece of code:

    """Friendly Python SSH2 interface."""
    
    import os
    import tempfile
    import paramiko
    
    class Connection(object):
        """Connects and logs into the specified hostname. 
        Arguments that are not given are guessed from the environment.""" 
    
        def __init__(self,
                     host,
                     username = None,
                     private_key = None,
                     password = None,
                     port = 22,
                     ):
            self._sftp_live = False
            self._sftp = None
            if not username:
                username = os.environ['LOGNAME']
    
            # Log to a temporary file.
            templog = tempfile.mkstemp('.txt', 'ssh-')[1]
            paramiko.util.log_to_file(templog)
    
            # Begin the SSH transport.
            self._transport = paramiko.Transport((host, port))
            self._tranport_live = True
            # Authenticate the transport.
            if password:
                # Using Password.
                self._transport.connect(username = username, password = password)
            else:
                # Use Private Key.
                if not private_key:
                    # Try to use default key.
                    if os.path.exists(os.path.expanduser('~/.ssh/id_rsa')):
                        private_key = '~/.ssh/id_rsa'
                    elif os.path.exists(os.path.expanduser('~/.ssh/id_dsa')):
                        private_key = '~/.ssh/id_dsa'
                    else:
                        raise TypeError, "You have not specified a password or key."
    
                private_key_file = os.path.expanduser(private_key)
                rsa_key = paramiko.RSAKey.from_private_key_file(private_key_file)
                self._transport.connect(username = username, pkey = rsa_key)
    
        def _sftp_connect(self):
            """Establish the SFTP connection."""
            if not self._sftp_live:
                self._sftp = paramiko.SFTPClient.from_transport(self._transport)
                self._sftp_live = True
    
        def get(self, remotepath, localpath = None):
            """Copies a file between the remote host and the local host."""
            if not localpath:
                localpath = os.path.split(remotepath)[1]
            self._sftp_connect()
            self._sftp.get(remotepath, localpath)
    
        def put(self, localpath, remotepath = None):
            """Copies a file between the local host and the remote host."""
            if not remotepath:
                remotepath = os.path.split(localpath)[1]
            self._sftp_connect()
            self._sftp.put(localpath, remotepath)
    
        def execute(self, command):
            """Execute the given commands on a remote machine."""
            channel = self._transport.open_session()
            channel.exec_command(command)
            output = channel.makefile('rb', -1).readlines()
            if output:
                return output
            else:
                return channel.makefile_stderr('rb', -1).readlines()
    
        def close(self):
            """Closes the connection and cleans up."""
            # Close SFTP Connection.
            if self._sftp_live:
                self._sftp.close()
                self._sftp_live = False
            # Close the SSH Transport.
            if self._tranport_live:
                self._transport.close()
                self._tranport_live = False
    
        def __del__(self):
            """Attempt to clean up if not explicitly closed."""
            self.close()
    
    def main():
        """Little test when called directly."""
        # Set these to your own details.
        myssh = Connection('example.com')
        myssh.put('ssh.py')
        myssh.close()
    
    # start the ball rolling.
    if __name__ == "__main__":
        main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to write a script that will tell another server to SVN
I would like to write a ruby script that will save the Json object
I would like to write a script which will edit multiple XML files, I
I would like to write a cross-platform function in C++ that contains system calls.
I would like to write an if statement that will do something base on
I would like to write a script that can receive e-mail and then do
I would like to write a python script that takes a bunch of swf
I'm trying to write a PowerShell script that will do the following: Executes a
I would like to write a script that logs into hotmail and changes the
I would like to write a script that checks out stuff from a repository

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.