R
R
Reshh4rd2018-03-31 20:59:03
Python
Reshh4rd, 2018-03-31 20:59:03

How to insert a variable into a command?

Paramiko module, I want to create a TEST file on a remote server that will contain the current date:
(TEST20180331)

import paramiko
import datatime
a = datetime.datetime.today().strftime("%Y%m%d")  ###текущая дата 
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.12.123.123', port=22, username='sshuser, password='123')
sftp = ssh.open_sftp()
stdin, stdout, stderr = ssh.exec_command ('touch /export/home/TEST???)           ###В bash я бы просто написал TEST$a

How to insert a variable in python3 ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2018-03-31
@Reshh4rd

по-быстрому 
('touch /export/home/TEST'+var)

по-правильному
('touch /export/home/TEST{0}'.format(var))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question