与非阻塞读的bash脚本 [英] Bash script with non-blocking read

查看:348
本文介绍了与非阻塞读的bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

欲一些数据发送到根进程与命名管道。下面是脚本,它的伟大工程:

I want to send some data to a root process with a named pipe. Here is the script and it works great:

#!/bin/sh
pipe=/tmp/ntp

if [[ ! -p $pipe ]]; then
    mknod -m 666 $pipe p
fi

while true
do
    if read line <$pipe; then
         /root/netman/extra/bin/ntpclient -s -h $line > $pipe 2>&1
    fi
done

我其实有像这样的几个脚本。我想附上所有的人都在一个脚本。问题是,在第一个读,我不能执行多个该执行模块在一个单一的过程中阅读。是不是有什么我可以做什么?是否有可能有一个无阻塞的bash读?

I actually have several script like this one. I would like to enclose all of them in a single script. The problem is that execution blocks on the first "read" and I cannot execute multiple "reads" in a single process. Isn't there anything I can do? Is it possible to have a "non-blocking" bash read?

推荐答案

只要把读周期划分为背景(添加&安培;完成之后)?

Just put the reading cycle into background (add & after done)?

这篇关于与非阻塞读的bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆