tags:

views:

86

answers:

2

I have my laptop, most of the time connected to internet, the speed of internet is quite slow. When i download some big files, then i am not able to surf web sites because of slow speed of internet. My plan is to write a bash script and run it in cron jobs, when it finds the system is idle then it starts a process(the process which will download the big files preferably wget) automatically and when i use the laptop then the process is killed. Similar to a screensaver( I have found some ways at http://stackoverflow.com/questions/622367/scheduling-in-linux-run-a-task-when-computer-is-idle-no-user-input but i dont use screensaver on my machine neither i want to depend on gnome application like xscreensaver ). I use Ubuntu linux, is there a way to find proper idle time of a Linux mahine.

idle = no keyboard, touch pad or mouse clicks.

Is there some way to find network activity in such way, like if their is no internet traffic then my sript start executing another wget script and if my browser request for web pages then it will stop executing the script.

please suggest me a proper way.. should i implement it using idle time, it will be more effective if i use network traffic into consideration.

A: 

I'd recommend a much simpler method: Just tell wget how much bandwith it may eat up, to leave some free for surfing the web.

Just use:

wget --limit-rate=1.5k http://example.com
Turbo J
i dont want to put bandwidth cap for my downloads, because i will do no good while the system is idle..
Idlecool
The only other method would be a custom script executed as a "screensaver". MUCH more difficult, and - depending how long your system is idle - it may not be faster even.
Turbo J
is it the only way to do that.. i wonder how the screensaver has been implemented. hope i can get some clue from it..
Idlecool
+1  A: 

There is one way but it's pretty hacky. You could listen to the appropriate devices (in the /dev area).

For example, on my current machine:

sudo cat /dev/input/by-path/platform-i8042-serio-0-event-kbd

Generates a whole load of bytes if I'm typing and blocks (outputs nothing) if I'm not. Something similar should work for the mouse but it doesn't seem to on my system.

By default the permissions for the input devices are pretty strict, you may want to chgrp them (for example). I would definitely not leave something like that running as root! Be aware there are lots of possible security implications of messing about with the permissions in dev. I would definately not consider this if it's a shared box.

This is not a simple program to write (you may be able to do it as a bunch of scripts signaling each other but I personally wouldn't) and using something like xscreensaver (or even just CPU usage) would be simpler (but perhaps less fun).

Henry Slater
that works for keyboard though.. but for mouse/touchpad it doesnt works even for me..
Idlecool