Issue
I'm trying to invoke a bash script on a container on a remote VM like below,
sshpass -p password ssh ubunt@${slave_ip} "kubectl exec -it pod_name -c container_name -- bash -c "/my_script.sh --${version} --${remote_ip} --${password} --${range} --${env}""
Problem being, only the 1st argument - version
gets parsed and the rest are lost.
What am I doing wrong & how to pass multiple arguments correctly using kubectl
, many thanks.
Solution
This should work better :
sshpass -p password ssh ubunt@${slave_ip} "kubectl exec -it pod_name -c container_name -- bash -c '/my_script.sh --${version} --${remote_ip} --\"${password}\" --${range} --${env}'"
even though it can still have problems if you $password
contains special characters like quotes, so try to think of different ways to pass it.
Update
I tested with sshpass, which worked as well.
Can you run following and post result ? (Notice the printf %s__
)
sshpass -p password ssh ubunt@${slave_ip} "kubectl exec -it pod_name -c container_name -- bash -c 'printf %s__ /my_script.sh --${version} --${remote_ip} --\"${password}\" --${range} --${env}'"
Answered By - Philippe Answer Checked By - Candace Johnson (WPSolving Volunteer)