1

I want to pass argument to shell script dynamically through paramiko. I tried but I can't achieve it. If anyone knows please let me know.

Below is my code:

Python code:

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect("192.168.10.5", username='root', password='root')
backup_name="test_backup"
stdin, stdout, stderr = client.exec_command('./backup.sh',backup_name)
stdin.write('next')
stdin.flush()

Shell Script(backup.sh):

#!/bin/bash

virsh snapshot-create-as one-96 "'$1'"

I want to create backup with the backup name mentioned in the python code through shell script. How to pass that name in exec_command to shell script? Thanks in Advance!!!!

3

1 Answer 1

1

To pass arguments to the exec_command, just use the following format:

exec_command(command, bufsize=-1, timeout=None, get_pty=False, environment=None)

For your example(exec_command('./backup.sh',backup_name)) you may do it this way:

exec_command(command='./backup.sh', bufsize=-1, timeout=None, get_pty=False, environment=dict(backup_name=backup_name))

Reference docs

Sign up to request clarification or add additional context in comments.

Comments

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.