3

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 ?

3
  • 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. Commented Dec 8, 2016 at 7:47
  • What command did you use to create these aliases and what shell are you using?
    – jlliagre
    Commented Dec 8, 2016 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
    Commented Dec 8, 2016 at 7:57

1 Answer 1

2

Aliases are for commands, you want variables here:

hy1=vahaidom@h1
hy2=vahai@master
for g in $hy1 $hy2; do scp kube.tar.gz ${g}: ; done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .