0

I'm writing a script that I'm running through a terminal, and would like it to run BASH commands in that same terminal. All solutions that I found were geared toward connecting remotely through SSH, whereas I just need to run SSH commands on the same machine.

Can someone please point in a direction how that can be done, since Googling didn't really give me relevant results.

Colonel Thirty Two
  • 23,953
  • 8
  • 45
  • 85
Neekoy
  • 2,325
  • 5
  • 29
  • 48
  • 2
    Exit out of Python and into the SSH shell? Or use the `subprocess` family of functions to spawn a shell. – Colonel Thirty Two Jun 11 '15 at 21:25
  • 1
    I would try using different wording in your google search, because I know there are already answers to this questions... http://stackoverflow.com/questions/4256107/running-bash-commands-in-python or http://stackoverflow.com/questions/26236126/how-to-run-bash-command-inside-python-script – ngoue Jun 11 '15 at 21:28
  • 1
    do you want to use ssh from python or you just want to run commands from python – Ubaidah Jun 11 '15 at 21:28
  • I need to run BASH commands within the Python script. I read about subprocess, however all references to it were for external SSH connections. Will check on it in a bit. Thanks for the help :) – Neekoy Jun 11 '15 at 22:02
  • Colonel Thirty Two, actually the end of my script would require to exit out of the Python script and run a Shell command using some variables from the script. Would that be possible with subprocess? – Neekoy Jun 11 '15 at 22:04

1 Answers1

2

You might be looking for the subprocess module. You can do (for example):

subprocess.call("<bash command here>", shell = True)

For more details check the documentation.

Aereaux
  • 845
  • 1
  • 8
  • 20
  • When I checked earlier, all references to the subprocess module were for external SSH connections which would be unnecessary for my purpose. Since I can run BASH commands with it on the local machine without a connection, this is definitely the answer I was looking for. Thank you :) – Neekoy Jun 11 '15 at 22:03