I have a script (actually, a Rails application with a Sidekiq job queue system), which uploads pictures and albums to Flickr. This data is huge for my purposes (around 100GB), and the upload is slow due to my low internet speed.

I have already configured the script to run when Ubuntu boots, as well as have init.d interface for controlling this script.

Now, since the uploading consumes all my bandwidth, I want to run this script only when the internet connection is idle, i.e. the script should pause automatically when the internet connection is being used by other applications, and resume once it becomes idle again.

So, I would like to know if there is a way that I can monitor my internet connection and check to see if other applications are connected online. If so, the script pauses itself, and resumes when the connection becomes idle again.

Any pointers or help in this regard is appreciated.

  • This will be hard because once the script decides to start it will never be able to tell when to stop.
    – Seth
    Sep 25, 2014 at 18:00
  • is (or can) the script be used on user level? (in that case not needed to start it on boot up), and what is the process name of the script? would it be acceptable for you if "internet idle" is defined by (not) running certain applications (firefox, thunderbird) Sep 25, 2014 at 18:06
  • Did you even notice my question(s) Sep 26, 2014 at 19:58

1 Answer 1


You can use /proc/net/dev to monitor network activity, something like this:

packets() {
    # Get the number of packets of eth0 device
    cat /proc/net/dev | grep eth0 | cut -f5 -d' ';


while [ true ]; do
    sleep 1;
    # I consider idle less than 10 packets per second
    if [ $DIFF -le 10 ]; then
        echo 'Idle!';

The trick here is what you consider idle, since zero traffic is a real world impossibility :)

  • 1
    but the upload script itself will cause "unidle", so either you would have to identify traffic by the script or use another method. (See @Seth 's comment) Sep 25, 2014 at 20:36
  • The OP says that he wants to upload pictures to Flickr, so he can upload 1 picture and check for idle to proceed to the next picture in an loop. Any other scenario would add too much complexity.
    – Vinicius
    Sep 26, 2014 at 17:20
  • I am pretty sure there must be another possibility, and 100 GB of pictures in a queue is probably not suited for what you suggest, although I don't have the solution (yet?). interesting question. Sep 26, 2014 at 17:26
  • Sure there is a better solution, but not using bash :)
    – Vinicius
    Sep 26, 2014 at 17:33
  • 1
    I think the better solution would be to implement this inside his Rails app. He could send a packet and monitor the interface throughput at the same time and decide if it would send the next packet or sleep a little.
    – Vinicius
    Sep 26, 2014 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.