I’m trying to come up with a bash script to automate some knife commands. The following knife command works just fine:
knife ssh -a ipaddress ‘name:mailserver’ “run some command here” -x myaccount -i .ssh/mykey.pem -C3
However, I need to write a script that substitutes a variable for the hostname. So I woudl do something like:
read hostnameVar # read in a hostname variable from the command line
knife ssh -a ipaddress ‘name:$hostnameVar’ “run some command here” -x myaccount -i .ssh/mykey.pem -C3
So that last line should run some command against the host variable $hostnameVar. I’ve not gotten it work. Here are the variations I’ve tried:
knife ssh -a ipaddress ‘name:$hostnameVar’ “run some command here” -x myaccount -i .ssh/mykey.pem -C3
knife ssh -a ipaddress “name:$hostnameVar” “run some command here” -x myaccount -i .ssh/mykey.pem -C3
knife ssh -a ipaddress name:$hostnameVar
“run some command here” -x myaccount -i .ssh/mykey.pem -C3
knife ssh -a ipaddress name:`$hostnameVar’ “run some command here” -x myaccount -i .ssh/mykey.pem -C3
I believe I’ve tried every combination of quotes, single quotes, and back tick with no luck. Is there a way to run knife against a variable that represents a hostname?
TIA