Defina isso como um aplicativo de inicialização:
#!/bin/bash
# Based on /etc/cron.daily/apt
check_stamp()
{
stamp=""
interval=""
if [ $interval -eq 0 ]; then
echo "check_stamp: interval=0"
# treat as no time has passed
return 1
fi
if [ ! -f $stamp ]; then
echo "check_stamp: missing time stamp file: $stamp."
# treat as enough time has passed
return 0
fi
# compare midnight today to midnight the day the stamp was updated
stamp_file="$stamp"
stamp=$(date --date=$(date -r $stamp_file --iso-8601) +%s 2>/dev/null)
if [ "$?" != "0" ]; then
# Due to some timezones returning 'invalid date' for midnight on
# certain dates (eg America/Sao_Paulo), if date returns with error
# remove the stamp file and return 0. See coreutils bug:
# http://lists.gnu.org/archive/html/bug-coreutils/2007-09/msg00176.html
rm -f "$stamp_file"
return 0
fi
now=$(date --date=$(date --iso-8601) +%s 2>/dev/null)
if [ "$?" != "0" ]; then
# As above, due to some timezones returning 'invalid date' for midnight
# on certain dates (eg America/Sao_Paulo), if date returns with error
# return 0.
return 0
fi
delta=$(($now-$stamp))
# intervall is in days, convert to sec.
interval=$(($interval*60*60*24))
echo "check_stamp: interval=$interval, now=$now, stamp=$stamp, delta=$delta (sec)"
# remove timestamps a day (or more) in the future and force re-check
if [ $stamp -gt $(($now+86400)) ]; then
echo "WARNING: file $stamp_file has a timestamp in the future: $stamp"
rm -f "$stamp_file"
return 0
fi
if [ $delta -ge $interval ]; then
return 0
fi
return 1
}
update_stamp()
{
stamp=""
touch $stamp
}
STAMP=
INTERVAL=
export DISPLAY=:0.0
while true; do
if check_stamp $STAMP $INTERVAL; then
# Do whatever you want
/path/to/your/script
# Update stamp
update_stamp $STAMP
fi
# Sleep 10 min
sleep 600
done
Substitua o /path/to/your/script (dentro do loop while) pelo caminho do seu script.
Chame esse script passando primeiro um caminho para um arquivo que servirá como um carimbo seguido por um intervalo em dias, por exemplo scriptname /home/user/stampfile 1 . Ele funcionará sem parar e verificará a hora atual contra o carimbo a cada 10 minutos ( sleep 600 ). Se a diferença for maior que o intervalo, ele executa o script e atualiza o carimbo.