Sam
Sam

Reputation: 37

How to add backspace in a Linux terminal command?

I need to execute the following command to ssh into a device on a network whose credentials have been saved.

ans = subprocess.check_output(['sudo','sshpass','-p',iplist[index][3],'ssh',iplist[index][2],'@',iplist[index][2]])

This is executed on Ubuntu in a Python environment. I want to actually execute-

sudo sshpass -p password username@hostname

It is quite possible that there is a space before and afer '@'. How do I eliminate that?

Upvotes: 2

Views: 257

Answers (2)

Shai
Shai

Reputation: 114786

You need to merge iplist[index][2],'@',iplist[index][2] into a single item in the list:

ans = subprocess.check_output(['sudo','sshpass','-p', iplist[index][3],'ssh','{}@{}'.format(iplist[index][2], iplist[index][2])])

Upvotes: 2

Nils Werner
Nils Werner

Reputation: 36757

Concatenate them to one argument

ans = subprocess.check_output(['sudo', 'sshpass', '-p', iplist[index][3], 'ssh', iplist[index][2] + '@' + iplist[index][2]])

Upvotes: 5

Related Questions