paul
paul

Reputation: 13481

Mount command cannot use xargs

I made this command.

  aws ec2 describe-instances --filters "Name=tag-value,Values=jenkins" |  jq '.Reservations[0].Instances[0].PrivateIpAddress' | mount -t nfs -o vers=4,nfsvers=4 xargs:/mnt/gradle /mnt/gradle

But seems like the xargs cannot be used in the mount command. This is the error

mount.nfs: Failed to resolve server xargs: Name or service not known

Any idea what is wrong

Upvotes: 0

Views: 310

Answers (2)

heemayl
heemayl

Reputation: 42117

Do it like:

.... | xargs -I'{}' mount -t nfs -o vers=4,nfsvers=4 <IP_or_hostname>:'{}' '{}'

Upvotes: 1

janos
janos

Reputation: 124804

It's not very clear what you're trying to do. But first let's make that line readable by breaking lines:

aws ec2 describe-instances --filters "Name=tag-value,Values=jenkins" | \
  jq '.Reservations[0].Instances[0].PrivateIpAddress' | \
  mount -t nfs -o vers=4,nfsvers=4 xargs:/mnt/gradle /mnt/gradle

You are trying to pipe to the mount command. That cannot work, because the mount command doesn't take parameters from stdin. To run mount for each line of stdin, you can use xargs:

aws ec2 describe-instances --filters "Name=tag-value,Values=jenkins" | \
  jq '.Reservations[0].Instances[0].PrivateIpAddress' | \
  xargs -I{} mount -t nfs -o vers=4,nfsvers=4 '{}':/mnt/gradle /mnt/gradle

I assume that the lines in stdin are ip addresses. For example if it contains the line 192.168.1.10, then the following command will get executed:

mount -t nfs -o vers=4,nfsvers=4 192.168.1.10:/mnt/gradle /mnt/gradle

However, if there are multiple lines in the input, I'm not sure what you expect to happen. With this example I gave, only the last server will be accessible via the local mount point /mnt/gradle.

Upvotes: 1

Related Questions