0

I have a file which contains host info, one host one line

host1
host2
host3

what I want to do is

ssh host1 'my command' 
ssh host2 'my command' 
ssh host3 'my command' 

how can I use one line command to implement it (not complex shell script), thanks

2 Answers 2

1

Is this too complex for what you want?

for h in $(<file); do ssh $h 'my command'; done

Another possibility:

cat file | xargs -I% -- ssh % 'my command'

or shorter:

<file xargs -I% -- ssh % 'my command'

or shorter if you are sure you don't have any - option in your ssh command:

<file xargs -I% ssh % 'my command'
Sign up to request clarification or add additional context in comments.

Comments

0
while read -r line; do ssh "$line" 'my command'; done < host

The command would read the file line by line, and save each line into the variable $line. And execute your ssh command with the host saving in $line

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.