0

With this command, I want to save an output of the smartctl command of the sda drive.

Now, since I use RAID, I have multiple drives, not just sda.

The following command works fine:

stdin, stdout, stderr = ssh.exec_command('/bin/su root -c "smartctl -a /dev/sda > /tmp/smartctl_output1"', get_pty=True) # ORIGINAL

I want to achieve that I pass local Python variable "DISK" containing sda, sdb, sdc and so on instead only static value.

The following line produces error:

stdin, stdout, stderr = ssh.exec_command('/bin/su root -c "smartctl -a /dev/" + DISK + " > /tmp/" + DISK', get_pty=True)
0

1 Answer 1

1

Your question has nothing to do with Paramiko.

It's just a trivial concatenation of strings in Python:

ssh.exec_command(
     '/bin/su root -c "smartctl -a /dev/' + DISK + ' > /tmp/' + DISK + '"',
     get_pty=True)

For even better options, see How to insert string into a string as a variable?

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.