K
kmh
Grünschnabel
Ich habe ein Shellskript gefunden, das "crond" emuliert.
Der Punkt, indem ich beim Verständnis nicht weiterkomme, ist folgende Passage:
Vor allem die Variable minute### ist mir suspekt ??
Ich würde mich sehr freuen wenn mir das jemand erklären könnte - bin leider noch kein Skript-Profi.
Code:
#!/bin/sh
# crond replacement
CRONTAB=/var/etc/crontab
# crontab format
# +---------minute 00-59
# | +-------hour 00-23
# | | +-----day of month 01-31
# | | | +---month 01-12
# | | | | +-day of week 1-7
# | | | | |
# * * * * * command
while true
do
remain=$(date +%S|sed 's/^0//')
sleep $((60-remain))
set $(date '+%M %H %d %m %w')
while read minute hour day month wday command
do
runit=""
if [ "${minute###}" != "$minute" ]
then
continue
fi
[ "$minute" = "$1" ] || [ "$minute" = "*" ] && runit=$runit"M"
[ "$hour" = "$2" ] || [ "$hour" = "*" ] && runit=$runit"H"
[ "$day" = "$3" ] || [ "$day" = "*" ] && runit=$runit"d"
[ "$month" = "$4" ] || [ "$month" = "*" ] && runit=$runit"m"
[ "$wday" = "$5" ] || [ "$wday" = "*" ] && runit=$runit"w"
if [ "$runit" = "MHdmw" ]
then
log="/tmp/log-$(date +%Y%m%d)"
echo "$(date) running $command" >> $log
$command >>$log 2>&1 &
fi
done < $CRONTAB
done
Der Punkt, indem ich beim Verständnis nicht weiterkomme, ist folgende Passage:
Code:
if [ "${minute###}" != "$minute" ]
then
continue
fi
Vor allem die Variable minute### ist mir suspekt ??
Ich würde mich sehr freuen wenn mir das jemand erklären könnte - bin leider noch kein Skript-Profi.