1

I'm trying to do the following from a python script:

  1. connect to remote server
  2. in that remote server create a Screen
  3. in that screen run a few commands
  4. exit

So I try the following:

import os
os.system('ssh -t -t myname@server')
os.system('nice -11 screen')

However, the last command does not execute on the server. I get into the server, but have no connection to it from the python script anymore. What I want to do now is create a screen session.

1 Answer 1

1

How about this:

import os
os.system('ssh -t -t myname@myserver "nice -11 screen"')

This leaves you at the screen.

Or if you just want to run a few commands:

import os
os.system('ssh -t -t myname@myserver "ls && pwd"')

This runs both these commands, then exits.

Edit:

The following will leave you at a shell prompt:

os.system('ssh -t -t myname@myserver "nice -11 screen -U"')

The following will run a command, then leave you at a shell prompt:

os.system('ssh -t -t myname@myserver "ls > ~/x.txt && nice -11 screen -U"')
Sign up to request clarification or add additional context in comments.

2 Comments

The problem is that the connection is immediately lost after I run any of the commands...
@ArashSaidi: See my edits...they will leave you at a prompt if that's what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.