Python script to connect to ssh and run commands in linux. We will be using the paramiko library; let's install it: pip3 install paramiko. connect(hostname=instance_ip, username="ubuntu", pkey=key) # Execute a command(cmd) after connecting/ssh to an instance. Passing the parameter shell=True the command gets invoked through the shell. I would like to capture the output of that script (its logging messages) and the exit code it returns. It supports ssh by providing the password but nevertheless, it cannot supplant the ssh command: 3. you should get "foo" as a response. These are associated with a particular key. I login to Windows Sep 28, 2023 · The easiest method to run a Python script on any Linux distribution is by invoking the python command and provide it with the name of your Python script. disown will keep the process running after you log out. Can some tell me where to start this basic script? You can flesh this out by setting a timeout and handling things that can go wrong (see snippet above). All you have to do is return the child from the ssh_login function and pass it along as an input to your other functions. system(myCmd) You can also store the output of the shell command in a variable in this way: import os. profile is not read. ssh/authorized_keys. Aug 22, 2017 · For subprocess ssh-run to work, ssh configuration needs to be in place. The result should look like this: Locating the Paramiko package to be installed. My requirement is: Run a Python/Powershell script from a windows box which should connect to Palo Alto by command line with SSH connection and run some commands, like "show user group list" or "show system disk-space", It should display the output on screen and store output in a file. Next execute commands remotely using ssh command from local file called commands. If you want to "background" already running tasks, then Ctrl + Z then run bg to put your most recent suspended task to background, allowing it to continue running. we need to run the wmiexec. This will create both a public and private key pair that are used to authenticate your connections securely. When you call it, save the child in a variable. **However, if you are trying to run a batch script located on a local linux/windows machine and your remote machine is Windows, and it consists of multiple lines using ** plink root@MachineB -m local_script. ssh/authorized_keys to allow proper setup, if needed, e. $ ssh user@server_name < commands. 168. p = pexpect. To run a command within a script, simply enter the command as you would in the command-line interface. You could use ssh forced commands. system() executes commands on the same machine. Please see the command below in python. /someaction. Mar 6, 2016 · Thus, I want to execute commands in the same channel. ssh/config for easier ssh call. response = ssm_client. 34. set_missing_host_key To connect remote machine through shell scripts , use below command: sshpass -p PASSWORD ssh -o StrictHostKeyChecking=no USERNAME@IPADDRESS. Paramiko's SFTPClient class allows you to get a file-like object to read data from a remote file in a Pythonic way. Mar 23, 2018 · I have a python script that establishes ssh connected using os. , the following input will list the / directory and echo a text. Improve this answer. That's why when you run something like: exec_command("cd /tmp"); exec_command("mkdir hello"); The dir "hello" is created in dir, and not inside tmp. command consists of 3 different parts: Nov 12, 2021 · In the above verbose snippet, the sshpass is searching for the password pattern (without P/p – “assword”) where it supplies the password to the ssh prompt. open('remote_filename') try: for line in remote_file: # process line. py &') and found that no process of executefile. Function ssh_command: This function takes four parameters: ip (IP address of the remote server), user (SSH username), passwd (SSH password), and command (the command to execute on the remote server). execute('your command') Basically what you need is not PuTTy, but a SSH module to Python. Using sendline () method. I just sends this command over ssh: python pythontest. it means I am able to send the commands successfully from script. Nov 16, 2022 · Simple bash syntax to run multiple commands on remote machine. Apr 13, 2015 · 2. RELATED: How to Brute-Force SSH Servers in Python. run([f'ls -al {thedir}'], shell=True) Because we directly used the user input, the user can run any command simply by appending it with a semicolon. A different way is to use python's os. Append command you wish to run: date uptime df -H. Jun 27, 2023 · Running SSH commands using the subprocess module. return child. Type in the shell (command prompt) uname -a or Jan 29, 2015 · It's a console application, so you can redirect its output to a file (what you cannot do with PuTTY). Individually SSHing in to the devices will take long time. The following command will run the Linux shell and get the free memory information of a remote computer. Dec 30, 2020 · When you provide a remote command to ssh, it assumes the command is not interactive. invoke_shell() Now you are able to send even sudo commands to the host. Also here is shown how to use it via ssh command. Is there a means to run a shell script found on the client on the server without copying it over first? – Aug 19, 2022 · To run a command “exec_command()” is called on the SSHClient with the command passed. system('ssh -X [email protected]') os. Running python directly will hang as python expects to be able to interact with stdin/stdout if not running a script. This function can be used as a replacement for os. Below is the code. bash_profile or ~/. Also we can run multiple commands conditionally as mentioned in above blog. For example: Mar 7, 2014 · 10. I used : stdin, stdout, stderr = ssh. SSHClient () ssh. Dec 29, 2023 · The script begins by importing the paramiko module. py in the following way. 2” and username is “Jayesh”. Under shell script you may need to disable host key checking: $ sshpass -p 't@uyM59bQ' ssh -o StrictHostKeyChecking=no username@server. I have tried various combinations of escaping double and single quotes in both python and the string itself and the use of grave Jan 7, 2024 · Using a subshell: Execute multiple commands within a subshell on the remote system, providing a clean environment for the commands. 5. connect(hostname='hostname', username='username', password='password') # run a command on the remote server. Alternatively, you can use a private key file instead of a password for authentication. Jun 14, 2022 · It can be done in different ways: Using run () method. NET, Python, etc. You can explicitly tell local ssh to allocate a pseudo-terminal on the remote side:-t Force pseudo-terminal allocation. sh. plink root@MachineB -m local_script. 2. – pip install paramiko. This will ensure that if the file's contents are valid, it will be executed without any problems. where IPADDRESS, USERNAME and PASSWORD are input values which need to provide in script, or if we want to provide in runtime use "read" command. The -h flag prevents hangup. This library provides the necessary functionality to create SSH connections in Python. import paramiko ssh=paramiko. Ctrl + Z followed by: bg. It provides a basic suite of operations for executing local or remote shell commands (normally or via sudo) and uploading/downloading files, as well as auxiliary functionality such as Dec 18, 2012 · When ssh'ing to the remote machine, how to handle when it prompts for RSA fingerprint authentication. exe -ssh user@host -pw password -m c:\path\command. login depending on your login shell). When running this Feb 7, 2023 · import paramiko. Further, I need to execute a program present on the remote machine. When you execute the command, the run () function waits for the command to complete. The syntax is as below: python3 < script-name> . This will show the list of detached screen sessions. It builds on top of Invoke (subprocess command execution and command-line features) and Paramiko (SSH protocol implementation), extending their APIs to complement one another and Sep 24, 2020 · I got some idea from your given code @lucasgvarela & came up with this which actually worked. For example, run uptime command and date command on a Linux box named ‘centos7’ as ‘vivek’ user: $ ssh vivek@centos7 "uptime && date". then. I login to Windows Python Script To ssh and Run Multiple Commands in Linux. I am thinking of creating a python script that will create a menu to login to any servers and after using ssh to login to the server, can I be able to execute commands in the server as the 'user' specified in the ssh. Apr 26, 2017 · I am trying to use a ssh connection to run a python script on "Bash on Windows". it wont work. Then I tried using other way as including a backward slash: stdin, stdout, stderr = ssh. Remedy: Welcome to Fabric! Fabric is a high level Python (2. profile (or ~/. spawn("ssh user@remote_computer") Dec 30, 2013 · ForceCommand Forces the execution of the command specified by ForceCommand, ignoring any command supplied by the client and ~/. When I try Unix command from Unix to create dir in Windows, I get exit 53 /usr/bin/ssh2 --password pass -l admin ip_address mkdir "C:\Temp\ALEX_TEST_EX" & When I write only /usr/bin/ssh2 --password pass -l admin ip_address, it is Ok. I've used this to send commands routers to update static routes, but it has many other uses. I tried a script but when I am in the remote server via SSH, the second line to execute the python script does not work. os. 2”. Note: Be aware of security considerations related to the use of the shell parameter. txt > output. 5 or higher) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks. Oct 17, 2022 · I've been scalping to find an explained python script to ssh to multiple Linux devices via ssh using paramiko. system(cmd) One of these arguments is a string which contains spaces but would ideally be passed as a single argument; for example: . connect(hostname=host, username=user, password=pass) Once you are connected, invoke the shell: shell = ssh. py " file under the scripts folder in python. This module should work both on Windows and Linux. However I cannot get the result in python again. exec_command('executefile. optional: create . client. Using spawn class. connect(server, username=username, password=password) ssh_stdin, ssh_stdout, ssh_stderr = ssh. server = ssh. I am able to create a folder from the script. NET, JSch, Paramiko, etc. I'm expecting something like: sshProcess = subprocess. To provide the password from the file, we can use the “-f” option of sshpass. The SSH Client running the python script may not have this file. Likewise your python script should run without password prompt interruption if you execute it from the shell. Here ls will run on the remote server and return the results to you. py Mar 13, 2024 · Next, open the terminal and install the Paramiko library using ‘pip install paramiko’. i wrote a script to connect to a host and execute one command I tried to run powershell commands over ssh on Windows server, and only your I wrote a generic script on Python that supports Windows and Unix ssh connection from Unix. send_command(. Only the first line of the script will be executed. Apr 14, 2022 · To run commands over ssh with Python, we can use the Paramiko library. Add your username in place of “Jayesh” and add your IP address in place of “10. I also tried using nohup but still, it is not working. If you want to use the output of the shell command, you can store it in a file directly from the shell command: import os. Executing a local script remotely: Run a local script containing multiple commands on the remote system. This will create a screen session and when you are done, you can use the keys ctrl-a-d to detach. If you are connecting through putty then your server should be (I think so) Unix/Linux. Feb 14, 2017 · One more thing if you are working with CISCO servers or Routers then its an inbuilt security to strip remote commands off ssh connection commands. Yes, you have to copy your python script to the remote server. system. Aug 13, 2021 · Execute the file with the following command: python key_based_login. com with password called t@uyM59bQ: $ sshpass -p 't@uyM59bQ' ssh username@server. Dec 12, 2023 · For example: If our IP address is “10. adress='192. Jul 20, 2015 · Each time you run exec_command, a new bash subprocess is being initiated. Remove the "interact" statement to have the script exit when done (you could use a shell loop to execute this for a number of hosts/devices). The ssh connection plugin will force pseudo-tty allocation via -tt when scripts are executed. Setting Host Key Policy: Feb 22, 2021 · Give it a try and confirm that the command works as epxected. ssh to linux system from windows. exec_command(cmd_to_execute) Oct 21, 2010 · Option 2: bg + disown. It provides the foundation for the high-level SSH library Fabric , which is what we recommend you use for common client use-cases such as running remote shell commands or transferring files. ssh user@host "cd DjangoFolder; pipenv run python manage. You can flesh this out by setting a timeout and handling things that can go wrong (see snippet above). For example, to run the ls command within a script, you would write: #!/bin/bash ls. /script. SSH (secure shell) is good for remotely managing machines using a secure connection. py \&') Sep 7, 2016 · PuTTY has the -m switch, that you can use to provide a path to a file with a list of commands to execute: putty. When you run ssh example. disown -h. ssh otherhost << EOF ls some_folder; . The response is returned as a tuple of (stdin, stdout, stderr) The response is returned as a tuple of Jun 28, 2022 · That’s the content of the directory where prog. g. E. Make sure an SSH server is available in the destination environment: a remote server or the default remote interpreter. The first thing you need to do when running a command remotely is create an SSH connection, this can be done with Paramiko's SSHClient object like so: import paramiko. Hence, you can use the ssh command line utility inside your subprocess run method. The next option I looked into was implementing an interactive shell using paramikos' invoke_shell() function: ssh = paramiko. An easy way to test that the basic environment is working is to create a test program (test. py was found running. 22:22 ssheth@jumpserver Step 2: $ ssh ssheth@localhost -p 13000 The other way I thought about was to enable public key based authentication on the final host from the jump server and simply run the below command: ssh ssheth@jumpserver "ssh ssheth@finalhost 'rpm -qa . ssm_client = boto3. ssh = paramiko. myCmd = 'ls -la > out. If the script resides in a directory that appears in your PATH variable, you can simply type. If Machine A is a Unix-based system, you can use: ssh root@MachineB 'bash -s' < local_script. Welcome to Paramiko! ¶. AutoAddPolicy()) # connect to the remote server. Jun 28, 2019 · Just to clarify, this install. This guide will show you how to use Python to connect and run commands over SSH using the Paramiko package. txt will, in your case, contain a path to your shell script, like: /home/user/myscript. pip install paramiko. 7, 3. # create an SSH client object. ). 0 Wed Sep 23 15:13 - 17:28 (02:14)' is a surprise on 192. send(command + "\n") This will open a shell interactively, if the server allows it. Paramiko Documentation. connect(host, username=user, password=psw, port=22) Jul 27, 2016 · os. py If a user outside of the Python script’s expected list accesses one of your servers, the Python script returns the following: Entry user4 pts/0 192. #!/usr/bin/env python. $ screen -r. The subprocess module needs no further installation. Plink Oct 30, 2013 · Login to ssh server called server. py ". com. set_missing_host_key_policy(paramiko. To transfer a file, use the following code: python sftp_client. Type “paramiko” without quotes in the new dialog window that appears. Below are the steps that need to be followed. The response is returned as a tuple of (stdin, stdout, stderr) The response is returned as a tuple of Sep 23, 2013 · The best way to connect to the remote server and execute commands is by using " wmiexec. Just run pip install impacket. run(‘ls -l’) To create a tunnel, use the following code: python Using the mentioned SSH module connecting to server and executing a command is rather simple: import ssh. bash. Jul 27, 2016 · os. call('ssh ' + <remote client>, <subprocess stuff>) lsProcess = subprocess. import paramiko. This happens in your case, sudo finds no terminal. SSHClient() ssh. mean i already ssh to one remote machine and then i am running some python scripts which checks file modification time of files on another remote machine. system() function : def livestream(): os. This applies to shell, command, or subsystem execution. Though for automation, your better use the Plink command-line connection since you want to execute commands via SSH, Fabric is definitely what you want. Examples of its basic usage are provided here and here. Here we will show and give a python script to run multiple commands on multiple servers and get output in excel. The syntax is as follows: $ ssh bar@foo "command1 && command2". txt. Where the commands. Deamon's name is pigpiod and it belongs to pigpio module ( controling Raspberry Pi's GPIO ), Ubuntu Mate 16. There is a wonderful module pexpect, which can access a remote computer using ssh (with password). Simply run command2 if command1 successful on a remote host called foo. txt )' This example will make a local copy of a remote /etc/passwd file to /tmp/passwd: $ ssh user@username '( cat /etc/passwd )' > /tmp/passwd This example will execute a script on the remote server. $ script1. 04. ssh ; python script. Then, generate SSH keys using the ‘ssh-keygen’ command. system('cd Desktop') #doesn't get executed on remote machine I know that os. call('ls', <subprocess stuff>) lsProcess. I am importing 'os' to execute the bash commands. Click the + button in the lower left of the packages list to install a new package. py, but didn't have the virtual environment location in the Path (which was needed for installed packages). One advantage of this approach is increased security, since in that case the key can't be used to get to a login shell. The idea is to connect to a remote Linux server over SSH, let the script do the required operations and return back to local, without need not to upload this script to a Mar 30, 2017 · Using the paramiko library - a pure python implementation of SSH2 - your python script can connect to a remote host via SSH, copy itself (!) to that host and then execute that copy on the remote host. 143. How about a Bash Here Document:. Try to run several commands in the same exec_command call. Here is a link on how to copy files to a remote server using putty. ssh/rc if present. that why i am looking for simple script which include ssh to remote machine along with password option in it. edited Aug 11, 2017 at 15:47. Going Further with Paramiko Dec 27, 2016 · The equally common situation, when there is some Bash script on a Linux machine and it needs to connect from it over SSH to another Linux machine and run this script there. Connection(host='host', username='user', private_key='key_path') result = server. AutoAddPolicy()) ssh. When I do that the ssh just connects and then shuts down again, without executing the python script. Feb 8, 2022 · To demonstrate, the following code allows us to run any shell command: import subprocess thedir = input() result = subprocess. py. It doesn't provide a pseudo-terminal to the command. It’s a standard Python library. 6+) implementation of the SSHv2 protocol 2, providing both client and server functionality. Apr 9, 2022 · So, I would be grateful if someone can help me with a script or single command that can do this. com, the ssh daemon starts a login shell for you, and the login shell reads your ~/. Mar 16, 2020 · Introduction. You can use the following code snippet to ssh to an EC2 instance and run some command from boto3. It's really nice for automation because you can get the stdout of the remote server, execute commands, use sudo, etc. See Using the command-line connection tool Plink. Feb 23, 2024 · By running commands in a dedicated SSH terminal, you can access data on a remote server or the default remote interpreter via an SSH tunnel, mainly upload and download files. This is I have had luck using the following code to run one bash command, in this case "uptime", but am not sure how to issue one command after another. py I'm using paramiko to establish the ssh connection. Paramiko is an SSH-wrapper library and Fabric is built on top of it. The key is to get your own channel Executing Interactive Commands in Python through Paramiko Part 1 Executing Interactive Commands in Python through Paramiko Part 2 In this two videos it's explained how to run interactive commands via paramiko Jul 10, 2013 · I am finding hard to run a process on a remote SSH server at background using Paramiko. And with Plink, you can actually provide the command If Machine A is a Windows box, you can use Plink (part of PuTTY) with the -m parameter, and it will execute the local script on the remote server. By going through it, I found the syntax: ssh username@hostname "command1; command2;commandN" Now, how to run command inside remote hots using SSH in Jenkins pipeline? Here is the solution: Jul 17, 2015 · For the remainder of your session you will be able to run commands like. bat. exe user@example. and then make the script executable: $ chmod +x script1. py is stored. # Here 'ubuntu' is user name and 'instance_ip' is public IP of EC2. The best way is to use screen (on the server) to start a session to run the command in and then disconnect the screen so it will keep running, and you can do other things, or just disconnect from the server. ssh user@host 'bash -c "command1; command2; command3"'. py) containing: print "foo". spawn("ssh root@"+device) #Do your usual login. I have googled "python ssh". Jul 28, 2013 · Here are the steps followed based on your reply: Step 1: ssh -L 13000:172. Every Linux admin wants a python script to ssh and runs multiple commands in Linux. Jun 13, 2021 · The following SSH command can be used to create a file remotely. Aug 24, 2017 · I need to run a deamon over a remote Linux machine, using SSH. Pseudo-ttys do not have a stderr channel and all stderr is sent to stdout. You can add the StrictHostKeyChecking=no option to ssh: ssh -o StrictHostKeyChecking=no -l username hostname "pwd; ls". Can someone please explain in the most appealing way how a python script to ssh to multiple Linux device and run commands works? Apr 24, 2016 · Project preferences in PyCharm where new packages are installed. sh "Argument with Spaces" where $1 is equal to "Argument with Spaces". I'm going to write first code for handling ssh commands on python and I did search over the stackoverflow and can see that there are several python libraries that can be used for handling commands passed through ssh, like paramiko, pexpect and perhaps some others. put(‘local_file’, ‘remote_file’) To run a command on the SSH server, use the following code: python sftp_client. Then we can use it by writing. To go back: $ screen -list. You can now use the SFTPClient object to transfer files, run commands, and manage tunnels. ssh. close() Sep 12, 2018 · Now connect to the remote host: ssh. Share. Aug 19, 2022 · To run a command “exec_command()” is called on the SSHClient with the command passed. import boto3. I found a few tweaked them and actually worked but i still cannot understand how it works. 90. $ screen. Defining some connection credentials: Aug 4, 2020 · I have to monitor 8 to 9 servers. Otherwise, you'll need to provide the full path (either absolute or relative). 15. finally: Mar 23, 2013 · Add the following line to the beginning script1. Aug 10, 2017 · @Macintosh_89 but i am running some scripts from one remote machine on another. After the remote computer is connected, I can execute other commands. g: i'm new on python. Typically you will log in to a server using the command-line ssh tool, or something like PuTTy or MobaXTerm. optional: use command in target . The ssh is established with this class: Aug 3, 2018 · that took care of finding the appropriate python and manage. This will disable the host key check and automatically add the host key to the list of known hosts. Syntax to use ssh to connect to a remote server: ssh jayesh@10. def ssh_login(device): child = pexpect. The first step is to create an instance of SSHClient and call its connect method with the hostname, username, and password of the remote server. Which will create " wmiexec. txt'. Create a new file named commands. Here is the sample to run PowerShell commands on EC2 instances. shell. The solution that ultimately worked for me is. 112' , is a remote Linux to run this Mar 9, 2023 · The basic syntax for running commands in a bash script is simple and straightforward. $ ssh user@hostname '( cd /tmp/ && touch ssh_file. client('ssm', region_name="us-west-2") # use region code in which you are working. If I do this: ssh user@server /usr/ Mar 6, 2016 · Thus, I want to execute commands in the same channel. session = ssh_login(my_device) 31. So far, as a absolutely beginner I have the following : Mar 20, 2019 · I just found this link helpful on how to run multiple commands on remote using SSH. Nov 15, 2010 · Fabric is a Python (2. txt: $ ssh server_name < commands. 4+) library designed to execute shell commands remotely over SSH, yielding useful Python objects in return. ssh remote_server ls without being prompted for a passphrase. I wish to use shell to invoke a script on a remote server. To connect remote machine through shell scripts , use below command: sshpass -p PASSWORD ssh -o StrictHostKeyChecking=no USERNAME@IPADDRESS. Paramiko is a pure-Python 1 (3. A command-line syntax is identical, an output redirection added: plink. When an authentication is done with that key, that command is run and the connection exits. The command is invoked by using the user's login shell with the -c option. Prepare to work in the SSH Terminal. sh 'some params' pwd . But now you can use SSM send_command from boto3 to run commands directly on ec2 instances. InstanceIds=[. To connect. Python Script To ssh and Run Multiple Commands in Linux. com -m c:\local\path\commands. Click the Install Package button. Executing commands that does not require sudo (for example- ls)- script runs OK, while those who need sudo, fails. Use screen. Particularly, I will need to read content of the files from the remote server Sep 15, 2023 · Step 1: Creating an SSHClient Instance. sh script is on the SSH server under the ssh's working directory. To install it, we run. txt using the cat command: $ cat > commands. Feb 23, 2017 · I would like to build an automation script for executing numerous commands on a remote server running linux, and check the "exit code" of each command and compare it with a statement. Dec 20, 2011 · The question is old but for the people who still come here via google search i want to give them this. 31. This means that: ssh-keygen on originating machine. After the installation let’s see how to automate the Linux commands. SSHClient() # automatically add the remote server's SSH key. If you depend on separated stdout and stderr result keys, please switch to a copy+command set of tasks instead of using script. Inside the python > Scripts > wmiexec. It is most useful inside a Match block. Assuming you have an open SSHClient: sftp_client = ssh_client. Inside the function, an instance of the SSHClient class is created. chdir() May 23, 2017 · 27. example. I have tried various combinations of escaping double and single quotes in both python and the string itself and the use of grave I wrote a generic script on Python that supports Windows and Unix ssh connection from Unix. py migrate;" A few points to note: "pipenv run" is running my command in Jun 2, 2017 · The common syntax to push a command into the background and detach it from the current shell session: nohup COMMAND & or nohup COMMAND >/dev/null 2>&1 & if you want to suspend the info-file created by nohup. 0. This script will execute the ls command when it is run, and display the Sep 11, 2019 · Background: Being active in ssh tag on Stack Overflow, one of frequent questions that come up, are about various hacks that people attempt, while trying to execute a command/script (or even an SFTP server) over an SSH on a remote Unix/Linux server server using a root account using various programming languages (C#, Java, VB. When you specify a command to run remotely (with or without -t), the ssh daemon starts an ordinary shell, so your . ) and SSH libraries (SSH. Stdin, stdout and stderr of the remote process will be available on your local running script. # declare credentials host = 'hostip' username = 'username' password = 'password'. Exe files won't work there, but the Python should be installed by default. open_sftp() remote_file = sftp_client. The other option is to use nohup in combination with & so you would have nohup <command> &. /some_other_action 'other params' EOF To avoid the problems mentioned by @Globalz in the comments, you may be able to (depending what you're doing on the remote site) get away with replacing the first line with In this tutorial, you will learn how to write a simple Python script to remotely execute shell commands on your Linux machine. The pexpect. ssh-copy-id to the target machine into the target account's . connect(host, username=user, password=psw, port=22) It will work if the script has multiple lines on linux. zprofile or ~/. Feb 23, 2019 · Please pardon me as I am a very new to any programming language. run () method can be called to execute a command and return its output. I have around 25 network devices combination of cisco, juniper, linux etc which i need to remotely access and run some basic cli commands to get the output. ssh hostname python test. Mar 31, 2019 · 6. Oct 11, 2023 · Running and executing multiple ssh command. Is there a way I can do multiple action after ssh is completed? like want to run few mysql query after ssh & check the output of the queries & do something based on that? – Aug 9, 2019 · Hi Team. Method 1: Using run () method. il if pg rd ky hg yq wk np nb