开发者

how to send/echo x (specific) number of messages in a shell script per sec

开发者 https://www.devze.com 2023-01-10 10:21 出处:网络
How can I send some specific number of, say 1000, messa开发者_JAVA百科ges (echo) per second to a file by a shell script?

How can I send some specific number of, say 1000, messa开发者_JAVA百科ges (echo) per second to a file by a shell script?

i.e. I want to echo 1000 such messages ("hi") per sec to a (tmp) file. echo "hi" >> tmp


Best you can do is this:

while :; do
    i=0
    while [ $i -lt 1000 ]; do
            echo hi >> tmp
            i=$((i+1))
    done
    sleep 1
done

The time to actually execute the commands in the inner while loop is not taken into account, so this will write slightly less messages per second.

0

精彩评论

暂无评论...
验证码 换一张
取 消