I tried to copy the zip file from localhost to two remote machines, I aliased my remote hostnames.

Hence I use the for loop like this

 for g in hy1 hy2;do scp kube.tar.gz $g:~;done

hy1,hy2- alias for remote hostnames

when I ran this command, It returns the following error

ssh: Could not resolve hostname hy1: Name or service not known

lost connection

ssh: Could not resolve hostname hy2: Name or service not known

lost connection

Is there any problem with using alias for file sharing, with loop ?

  • For most shells (I believe zsh is an exception), a shell alias is only used for the command/utility name i.e. the first token of a command. You can set a shell variable and use that with $ anywhere (except singlequotes). For hostnames in scp and ssh you can configure nicknames or other synonyms in ssh_config q.v. – dave_thompson_085 Dec 8 '16 at 7:47
  • What command did you use to create these aliases and what shell are you using? – jlliagre Dec 8 '16 at 7:56
  • @jlliagre Iam using bash shell, I add alias in .bashrc file alias hy1='ssh vahaidom@h1' alias hyp='ssh vahai@master' – SuperKrish Dec 8 '16 at 7:57

Aliases are for commands, you want variables here:

for g in $hy1 $hy2; do scp kube.tar.gz ${g}: ; done
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.