Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 376447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:36:00+00:00 2026-05-12T14:36:00+00:00

I have been trying for about an hour now to find an elegant solution

  • 0

I have been trying for about an hour now to find an elegant solution to this problem. My goal is basically to write a bandwidth control pipe command which I could re-use in various situations (not just for network transfers, I know about scp -l 1234). What I would like to do is:

  1. Delay for X seconds.
  2. Read Y amount (or less than Y if there isn’t enough) data from pipe.
  3. Write the read data to standard output.

Where:

  • X could be 1..n.
  • Y could be 1 Byte up to some high value.

My problem is:

  • It must support binary data which Bash can’t handle well.

Roads I’ve taken or at least thought of:

  • Using a while read data construct, it filters all white characters in the encoding your using.
  • Using dd bs=1 count=1 and looping. dd doesn’t seem to have different exit codes for when there were something in if and not. Which makes it harder to know when to stop looping. This method should work if I redirect standard error to a temporary file, read it to check if something was transfered (as it’s in the statistics printed on stderr) and repeat. But I suspect that it’s extremely slow if used on large amounts of data and if it’s possible I’d like to skip creating any temporary files.

Any ideas or suggestions on how to solve this as cleanly as possible using Bash?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:36:00+00:00Added an answer on May 12, 2026 at 2:36 pm

    It’s not much elegant but you can use some redirection trick to catch the number of bytes copied by dd and then use it as the exit condition for a while loop:

    while [ -z "$byte_copied" ] || [ "$byte_copied" -ne 0 ]; do 
        sleep $X; 
        byte_copied=$(dd bs=$Y count=1 2>&1 >&4 | awk '$2 == "byte"{print $1}'); 
    done 4>&1
    

    However, if your intent is to limit the transfer throughput, I suggest you to use pv.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get this seemingly simple problem fixed for about half
I have been trying to figure this out for about a hour and can't
So, I have been trying to fix this for about two months. It all
Good evening, I have been trying to wrap my head about this, below, code
I have been trying to find info on the web about the differences between
I have been trying to find out more about Voldemort but it doesn't seem
This has been driving me insane for about the last hour. I'm trying to
I have been trying for about a day now to get an xml feed
I know there have been plenty of questions about this, but I've been trying
Probably a silly question here but I have been trying to find this for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.