updatedb
Alexander Boström
abo at kth.se
Wed Mar 23 21:55:12 UTC 2005
ons 2005-03-23 klockan 19:32 +0000 skrev Michael A. Peters:
> Is there an easy way to have updatedb run when cron tells it to but NOT
> at some random DVD buffer underrun coaster making time when it was
> powered off at cron time?
Well, in general, don't run cron jobs when the machine is doing
something else. The code below won't work very well, but it's a start.
And no, I don't know awk.
$ cat /etc/cron.daily/000-loadwait
#!/bin/bash
/usr/local/bin/loadwait 0.5 14400
$ cat /usr/local/bin/loadwait
#!/bin/bash
# . is decimal point
export LC_ALL=C
if [ $# -ge 1 ]; then
maxload=$1
else
maxload=0.5
fi
if [ $# -ge 2 ]; then
maxwait=$2
deadline=$(awk </proc/uptime '{print $1 + '$maxwait'}')
else
deadline=no
fi
maxsleep=60
while [ $(awk </proc/loadavg '{print $3 < '$maxload'}') -eq 0 ]; do
if [ $deadline == no ]; then
sleep $maxsleep
else
waitleft=$(awk </proc/uptime '{print '$deadline' - $1}' | sed 's,\..*,,')
if [ $waitleft -le 0 ]; then
exit
fi
if [ $waitleft -lt $maxsleep ]; then
sleep $waitleft
else
sleep $maxsleep
fi
fi
done
/abo
More information about the fedora-list
mailing list