利用管道和文件描述符實現多進程併發
#!/bin/bash
file_url="/usr/src/mytemp/2020"
mkfifo $file_url
exec 88<>$file_url
rm -fr $file_url
for i in {1..4}
do
echo >&88
done
base_ip="192.168.12.0"
for index in {1..30}
do
{
read -u 88
ip="${base_ip%.*}.${index}"
nmap $ip -sP &> /dev/null
if [ $? -ne 0 ];then
echo "ping ${ip} is successful"
else
echo "ping ${ip} is failed"
fi
echo >&88
}&
done
wait
exec 88<&-
echo "end"