OneAM Midnight
OneAM Midnight

Reputation: 1

how to use raw_input value for hostname

How do I take the raw input and use that as the "host" in the scp function?

host = raw_input('Hostname: ')
filename = "/Volumes/Data/puppet/puppet-enterprise-3.0.1-el-6-x86_64.tar.gz"

os.system("scp filename username@${host}:/home/username")
client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect(host)
stdin, stdout, stderr = client.exec_command('tar -zxvf /home/username/puppet-enterprise-3.0.1-el-6-x86_64.tar.gz')

Upvotes: 0

Views: 183

Answers (2)

Hai Vu
Hai Vu

Reputation: 40723

You need to modify your line slightly:

os.system("scp filename username@{0}:/home/username".format(host))

The format() function will replace host for {0}.

Upvotes: 1

Ankur Ankan
Ankur Ankan

Reputation: 3066

You just need to create the command by concatenating the host in between. This should work:

os.system("scp filename username@" + host + ":/home/username")

Upvotes: 0

Related Questions