Re: Cron Job jeden Tag früher starten
Am 2005-11-24 13:29:01, schrieb Ante Damjanovic??:
> Hello,
>
> hab da ein "kleines" Problem mit cron.
> Ich möchte jeden Tag zu einer anderen Zeit einen Job startetn.
> Genauer gesagt an einen Tag um 18:00 am nächsten um 16:00 dann um 14:00 ...
> also jeden Tag um 2h früher, daher wiederholt sich der Zyklus auch nach
> 12 Tagen.
> Nun meine Frage ob bzw. wie ich das mit cron realisieren kann?
____( 'crontab.conf' )____________________________
# start our script 2 minits after each full hour
2 * * * * $HOME/bin/licht_ein_aus_script
__________________________________________________
Datei anlegen und mit 'crontab crontab.conf' aktivieren
und eine Date wie
____( '~/bin/licht_ein_aus_script' )________________________
#!/bin/bash
# Set the time difference
let TIMEDIFF=-2
# Set the first hour to execute
let FIRSTHOUR=22
# Make sure, our private ~/tmp exist
if [ ! -d ~/tmp ] ; then mkdir -p ~/tmp ; fi
# Make sure, we have this file, because
# otherwise 'cat' will return an error.
if [ -f ~/tmp/licht_ein_aus_script.execute ] ; then
# Read the hour when to execute
let EHOUR=`cat ~/tmp/licht_ein_aus_script.execute`
else
# This set the very FIRST hour of execution
# if there is no file yet.
echo -n "$FIRSTHOUR" >~/tmp/licht_ein_aus_script.execute
let EHOUR=$FIRSTHOUR
fi
# Get the current time and strip preceeding <space>
let CHOUR=`date +%k |sed "s/\ //"`
# Execute our script if EHOUR (execute hour)
# is the same as CHOUR (current hour)
if [ $EHOUR -eq $CHOUR ] ; then
# Set the new HOUR to execute
let NHOUR=$CHOUR$TIMEDIFF
# Set the NHOUR (new executionhour)
# to the FIRSTHOUR if NHOUR negativ
if [ $NHOUR -lt 0 ] ; then let NHOUR=$FIRSTHOUR ; fi
# save the new execution time
echo -n "$NHOUR" >~/tmp/licht_ein_aus_script.execute
#
# HIER DEIN CODE DER LICHT EIN ODER AUS SCHALTET
#
fi
____________________________________________________________
anlegen. Getestet und funktioniert unter Woody, Sarge und Etch.
Greetings
Michelle
--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack Apt. 917 ICQ #328449886
50, rue de Soultz MSM LinuxMichi
0033/3/88452356 67100 Strasbourg/France IRC #Debian (irc.icq.com)
Reply to: