2011-02-22 10:59:45 [cron] Script doesn't stop
Gilles Ganault (FRANCE)
Message: 98338
Hello
Since "at" is not available for uClinux, a work-around I'm trying to use is to write a small Lua script which...
1. will be triggered by the main application,
2. make a copy of crontab before adding itself to it so the script is called a second time one minute later,
3. and then finally, remove itself by deleting the modified crontab and renaming the copy.
For some reason I can't figure, the script keeps running, altough it's no longer part of crontab the second time the script is ran :-/
Is there some feature in the uClinux version of cron (1.0-1) and/or in the Yaffs2 filesystem that could explain this behavior?
Here's the script:
====================
#!/var/tmp/lua
CRONTAB="/etc/config/crontab"
CRONTAB_COPY="/etc/config/crontab.orig"
MYSELF="/var/tmp/cron.lua"
-- read /etc/config/crontab
local file = assert(io.open (CRONTAB,"r"))
data = file:read("*a")
file:close()
-- check if file contains reference to cron.lua
-- HERE: WHY DOES SCRIPT KEEP RUNNING PAST THE SECOND RUN?
if(string.find(data, MYSELF)) then
-- remove job from crontab by deleting current and renaming original
command = string.format("rm %s",CRONTAB)
os.execute(command)
command = string.format("mv %s %s",CRONTAB_COPY,CRONTAB)
os.execute(command)
else
-- cp original crontab, and add MYSELF to copy
command = string.format("cp %s %s",CRONTAB,CRONTAB_COPY)
os.execute(command)
-- Add myself to crontab so am run a second time in 1mn
local file = assert(io.open (CRONTAB,"a"))
file:write("*/1 * * * * root ",MYSELF,"\n")
file:close()
end
====================
Thank you.
QuoteReplyEditDelete
2011-02-22 17:30:35 Re: [cron] Script doesn't stop
Mike Frysinger (UNITED STATES)
Message: 98344
the embedded cron might act differently, but typically cron's need to be told when the config file is updated. this happens by running `crontab <config file>`. otherwise, they maintain their own internal state.
QuoteReplyEditDelete
2011-02-25 05:24:44 Re: [cron] Script doesn't stop
Gilles Ganault (FRANCE)
Message: 98439
Thanks for the tip. The appliance doesn't have a "crontab" binary. I'll just stop cron, edit its crontab configuration file, and start cron, and perform the same operation in the script that is called by cron.