I have a list of servers in a file that I pass to the following script:
#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
ssh_cmd="user@$line"
ssh $ssh_cmd 'hostname && ls -l /path/to/folder | grep some_token' &
done < "$1"
What I want is output like this:
output from hostname (1)
output from ls -l (1)
output from hostname (2)
output from ls -l (2)
output from hostname (3)
output from ls -l (3)
But these seem to be mixed up:
output from ls -l (1)
output from hostname (1)
output from hostname (2)
output from ls -l (2)
output from ls -l (3)
output from hostname (3)
Is there some way to ensure that these commands happen sequentially?
Thanks in adv!