Linked by Jussi Pakkanen on Tue 17th Apr 2007 18:20 UTC
Editorial Let me begin by telling you a little story. Some time ago I needed to run a script at work once a day. We had tons of machines ranging from big Unix servers to Linux desktops. Due to various reasons the script could only be run on a desktop machine. However using cron was disabled on desktops. All other machines allowed cron.
Thread beginning with comment 231709
To read all comments associated with this story, please click here.
A rebelious approach
by blixel on Tue 17th Apr 2007 21:40 UTC
blixel
Member since:
2005-07-06

Write a shell script that does what you want but uses so much CPU time they will gladly give you cron job access just to get you to quit using the "work around".

#!/bin/sh
while true ; do
if [ "$(date +%k:%M)" = "05:00" ] ; then
do_something_important ;
fi ;
done ;

Note: The functional part of that script will run for the entire minute of 5:00 a.m. Add a check to make it only run once. For the other 1,439 minutes of the day, it will just peg the CPU at 100% for no good reason.

Edited 2007-04-17 21:46

Reply Score: 5

RE: A rebelious approach
by flanque on Tue 17th Apr 2007 22:57 in reply to "A rebelious approach"
flanque Member since:
2005-12-15

That really is something that someone who isn't thinking would do. It would be stupid to implement something that consumes the CPU like that when you only need it for 1 minute a day.

A good example, none the less.. of what NOT to do. :-)

Reply Parent Score: 4

RE[2]: A rebelious approach
by Doc Pain on Tue 17th Apr 2007 23:07 in reply to "RE: A rebelious approach"
Doc Pain Member since:
2006-10-08

"It would be stupid to implement something that consumes the CPU like that when you only need it for 1 minute a day."

Isn't it what USB host adapters do with polling (unlike standard interrupt driven serial ports)? :-)

"A good example, none the less.. of what NOT to do. :-)"

I think we need a HOWNOTTO here. :-)

Reply Parent Score: 3

RE[2]: A rebelious approach
by gustl on Wed 18th Apr 2007 13:14 in reply to "RE: A rebelious approach"
gustl Member since:
2006-01-19

I really once progged something ALMOST that stupid ;) .

I have a Rollei slide projector which has an RS232 interface to the computer.
When I wrote a program which lets me "remote control" the projector by the computer I had a problem: How to waste time as efficient as possible?
I was (and am) no great shakes at timers, especially as I wanted to get my timing correct within 1/10th of a second, and the standard Linux timers allowed only for 1 second granularity.

I started with adding and subtracting 1 to a variable within a loop, but as you can guess, this led to 100% CPU utilisation. I ended up with asking the projector for its status, which led to maximum traffic on the 9600baud RS232, but at least kept my CPU at sane 8%.

:)

Reply Parent Score: 1