multi-process script for ping host

#!/bin/bash

#How many threads you want to concurrent
threadnum=3

#set file description to 8
tempfifo="/tmp/$$.fifo"
mkfifo $tempfifo
exec 8<>$tempfifo
rm -f $tempfifo

#List for what things you want to do
iplist="192.168.1.7 202.98.96.1 www.baidua.com 1.1.1.71"

#Define function, process what did you want to do
ping_sub()
{
    ping -c 3 $1 >/dev/null 2>&1
}

#
for ((i=0; i<$threadnum; i++));
do
{
    echo >&8
}
done

for ip in $iplist;
do
{
    read -u8
    ping_sub $ip  && echo "Host $ip was online" ||echo "Host $ip was offline"
    echo >&8
} &
done

wait

exec 8>&-
 

你可能感兴趣的:(function,process,things)