I have this
#! /bin/bash
cd ~
hostname=`hostname`
cat /opt/ip.txt | while read line;
do
# do something with $line here
RES=`ping -c 2 -q $line | grep "packet loss"`
echo "---" >> /opt/os-$hostname.txt
echo "---"
echo "$line $RES" >> /opt/os-$hostname.txt
echo "$line $RES"
done
How I can make the script multi-threaded? I would like to speed up the performance.
You can use the
<(...)
notation for starting a subprocess and thencat
all the outputs together:To use a loop for this, you will need to build the command first:
If you really want the delimiting
---
of your original, I propose to add anecho "---"
in themyping
.If you want to append the output to a file as well, use
tee
: