Lines 85-97
FCRONTAB_FILE_TMP=
Link Here
|
85 |
|
85 |
|
86 |
cleanup() { |
86 |
cleanup() { |
87 |
# remove temporary file (if any) |
87 |
# remove temporary file (if any) |
88 |
[ -e "$FCRONTAB_FILE_TMP" ] && rm -f $FCRONTAB_FILE_TMP |
88 |
[ -e "$FCRONTAB_FILE_TMP" ] && rm -f "$FCRONTAB_FILE_TMP" |
89 |
} |
89 |
} |
90 |
trap "eval cleanup" INT TERM HUP |
90 |
trap "eval cleanup" INT TERM HUP |
91 |
|
91 |
|
92 |
if [ -x "`type -p mktemp`" ]; then |
92 |
FCRONTAB_FILE_TMP="`mktemp /tmp/fcrontab.XXXXXX 2>/dev/null`" |
93 |
FCRONTAB_FILE_TMP=`mktemp /tmp/fcrontab.XXXXXX` |
93 |
if [ $? -ne 0 ]; then |
94 |
else |
|
|
95 |
FCRONTAB_FILE_TMP=/tmp/fcrontab.$$ |
94 |
FCRONTAB_FILE_TMP=/tmp/fcrontab.$$ |
96 |
fi |
95 |
fi |
97 |
|
96 |
|
Lines 136-142
VERBOSE=
Link Here
|
136 |
FORCE= |
135 |
FORCE= |
137 |
|
136 |
|
138 |
# read command line arguments |
137 |
# read command line arguments |
139 |
while [ "$#" -gt 0 ]; do |
138 |
while [ $# -gt 0 ]; do |
140 |
case "$1" in |
139 |
case "$1" in |
141 |
-v) |
140 |
-v) |
142 |
VERBOSE=true |
141 |
VERBOSE=true |
Lines 186-193
if [ -n "$FCRONTAB_PROG" ]; then
Link Here
|
186 |
[ -d "$FCRONTAB_PROG" ] && FCRONTAB_PROG="$FCRONTAB_PROG/fcrontab" |
185 |
[ -d "$FCRONTAB_PROG" ] && FCRONTAB_PROG="$FCRONTAB_PROG/fcrontab" |
187 |
[ ! -x "$FCRONTAB_PROG" ] && die "Invalid fcrontab executable or path specified with -p!" |
186 |
[ ! -x "$FCRONTAB_PROG" ] && die "Invalid fcrontab executable or path specified with -p!" |
188 |
else |
187 |
else |
189 |
if [ -x "`type -p fcrontab`" ]; then |
188 |
fcrontab -V 2>/dev/null |
190 |
FCRONTAB_PROG="`type -p fcrontab`" |
189 |
if [ $? -eq 0 ]; then |
|
|
190 |
FCRONTAB_PROG=fcrontab |
191 |
elif [ -x /usr/bin/fcrontab ]; then |
191 |
elif [ -x /usr/bin/fcrontab ]; then |
192 |
FCRONTAB_PROG=/usr/bin/fcrontab |
192 |
FCRONTAB_PROG=/usr/bin/fcrontab |
193 |
elif [ -x /usr/local/bin/fcrontab ]; then |
193 |
elif [ -x /usr/local/bin/fcrontab ]; then |
Lines 202-259
if [ -z "$CROND_DIR" -o -z "$CRONTAB_FIL
Link Here
|
202 |
die "Must specify all system crontab files." |
202 |
die "Must specify all system crontab files." |
203 |
fi |
203 |
fi |
204 |
|
204 |
|
205 |
# Function to scan for valid files in $CROND_DIR |
|
|
206 |
crond_files() |
207 |
{ |
208 |
[ ! -d $CROND_DIR ] && return |
209 |
local FILES=`echo $CROND_DIR/*` |
210 |
local FILE |
211 |
[ "$FILES" = "$CROND_DIR/*" ] && return |
212 |
for FILE in $FILES; do |
213 |
if [ ! -d $FILE -a $FILE = "${FILE%\~}" ]; then |
214 |
echo $FILE |
215 |
fi |
216 |
done |
217 |
} |
218 |
|
219 |
|
220 |
# Function to build up a system crontab and tell fcron it's changed |
205 |
# Function to build up a system crontab and tell fcron it's changed |
221 |
rebuild_and_notify() |
206 |
rebuild_and_notify() |
222 |
{ |
207 |
{ |
223 |
logger -i -p cron.notice -t "check_system_crontabs" "Rebuilding the system fcrontab..." |
208 |
logger -i -p cron.notice -t "check_system_crontabs" "Rebuilding the system fcrontab..." |
224 |
|
209 |
|
225 |
# put a warning message at the top of the file |
210 |
# put a warning message at the top of the file |
226 |
echo -e "########################################" > $FCRONTAB_FILE_TMP |
211 |
cat <<_EOF_ > "$FCRONTAB_FILE_TMP" |
227 |
echo -e "# WARNING!!! DO NOT EDIT THIS FILE!!! #" >> $FCRONTAB_FILE_TMP |
212 |
######################################## |
228 |
echo -e "########################################" >> $FCRONTAB_FILE_TMP |
213 |
# WARNING!!! DO NOT EDIT THIS FILE!!! # |
229 |
echo -e "# Do not edit this file! It is automatically generated from" >> $FCRONTAB_FILE_TMP |
214 |
######################################## |
230 |
echo -e "# the $CRONTAB_FILE, the $FCRONTAB_FILE and $CROND_DIR/* files whenever one of" >> $FCRONTAB_FILE_TMP |
215 |
# Do not edit this file! It is automatically generated from |
231 |
echo -e "# those files is changed.\n#\n\n" >> $FCRONTAB_FILE_TMP |
216 |
# the $CRONTAB_FILE, the $FCRONTAB_FILE and $CROND_DIR/* files whenever one of |
|
|
217 |
# those files is changed. |
218 |
# |
219 |
|
220 |
_EOF_ |
232 |
|
221 |
|
233 |
# include the standard system crontab file if it exists and is not a symbolic link |
222 |
# include the standard system crontab file if it exists and is not a symbolic link |
234 |
if [ -f $CRONTAB_FILE -a ! -L $CRONTAB_FILE ]; then |
223 |
if [ -f "$CRONTAB_FILE" -a ! -L "$CRONTAB_FILE" ]; then |
235 |
echo -e "\n\n########################################\n# $CRONTAB_FILE\n########################################\n" >> $FCRONTAB_FILE_TMP |
224 |
cat - "$CRONTAB_FILE" <<_EOF_ >> "$FCRONTAB_FILE_TMP" |
236 |
cat $CRONTAB_FILE >> $FCRONTAB_FILE_TMP |
225 |
|
|
|
226 |
|
227 |
######################################## |
228 |
# $CRONTAB_FILE |
229 |
######################################## |
230 |
|
231 |
_EOF_ |
237 |
fi |
232 |
fi |
238 |
|
233 |
|
239 |
# print a nice filename header for each file in /etc/cron.d/ |
234 |
# print a nice filename header for each file in /etc/cron.d/ |
240 |
# and include its contents into the new fcron system crontab |
235 |
# and include its contents into the new fcron system crontab |
241 |
for i in `crond_files` ; do |
236 |
for i in "$CROND_DIR"/* ; do |
242 |
echo -e "\n\n########################################\n# $i\n########################################\n" >> $FCRONTAB_FILE_TMP |
237 |
if [ -r "$i" -a ! -d "$i" -a "$i" = "${i%\~}" ]; then |
243 |
cat $i >> $FCRONTAB_FILE_TMP |
238 |
cat - "$i" <<_EOF_ >> "$FCRONTAB_FILE_TMP" |
|
|
239 |
|
240 |
|
241 |
######################################## |
242 |
# $i |
243 |
######################################## |
244 |
|
245 |
_EOF_ |
246 |
fi |
244 |
done |
247 |
done |
245 |
|
248 |
|
246 |
# include the system fcrontab file if it exists and is not a symbolic link |
249 |
# include the system fcrontab file if it exists and is not a symbolic link |
247 |
if [ -f $FCRONTAB_FILE -a ! -L $FCRONTAB_FILE ]; then |
250 |
if [ -f "$FCRONTAB_FILE" -a ! -L "$FCRONTAB_FILE" ]; then |
248 |
echo -e "\n\n########################################\n# $FCRONTAB_FILE\n########################################\n" >> $FCRONTAB_FILE_TMP |
251 |
cat - "$FCRONTAB_FILE" <<_EOF_ >> "$FCRONTAB_FILE_TMP" |
249 |
cat $FCRONTAB_FILE >> $FCRONTAB_FILE_TMP |
252 |
|
|
|
253 |
|
254 |
######################################## |
255 |
# $FCRONTAB_FILE |
256 |
######################################## |
257 |
|
258 |
_EOF_ |
250 |
fi |
259 |
fi |
251 |
|
260 |
|
252 |
# Replace "@hourly" style Vixie cron extensions which fcron doesn't parse |
261 |
# Replace "@hourly" style Vixie cron extensions which fcron doesn't parse |
253 |
sed -i -e "s/@yearly/0 0 1 1 */g" -e "s/@annually/0 0 1 1 */g" -e "s/@monthly/0 0 1 * */g" -e "s/@weekly/0 0 * * 0/g" -e "s/@daily/0 0 * * */g" -e "s/@midnight/0 0 * * */g" -e "s/@hourly/0 * * * */g" $FCRONTAB_FILE_TMP |
262 |
sed -i -e "s/@yearly/0 0 1 1 */g" -e "s/@annually/0 0 1 1 */g" -e "s/@monthly/0 0 1 * */g" -e "s/@weekly/0 0 * * 0/g" -e "s/@daily/0 0 * * */g" -e "s/@midnight/0 0 * * */g" -e "s/@hourly/0 * * * */g" "$FCRONTAB_FILE_TMP" |
254 |
|
263 |
|
255 |
# notify fcron about the updated file |
264 |
# notify fcron about the updated file |
256 |
$FCRONTAB_PROG -c $FCRON_CONFIG_FILE $FCRONTAB_FILE_TMP -u systab |
265 |
"$FCRONTAB_PROG" -c "$FCRON_CONFIG_FILE" "$FCRONTAB_FILE_TMP" -u systab |
257 |
} |
266 |
} |
258 |
|
267 |
|
259 |
NEED_REBUILD=0 |
268 |
NEED_REBUILD=0 |
Lines 274-284
if [ -n "$FORCE" ]; then
Link Here
|
274 |
|
283 |
|
275 |
else |
284 |
else |
276 |
|
285 |
|
277 |
if [ -d $CROND_DIR ]; then |
286 |
if [ -d "$CROND_DIR" ]; then |
278 |
|
287 |
|
279 |
# This test works for file creation/deletion (deletion is not detected |
288 |
# This test works for file creation/deletion (deletion is not detected |
280 |
# by the next test) |
289 |
# by the next test) |
281 |
if [ $CROND_DIR -nt $FCRONTABS_DIR/systab.orig ]; then |
290 |
if [ -n "$(find "$CROND_DIR" -prune -type d -newer "$FCRONTABS_DIR"/systab.orig 2>/dev/null)" ]; then |
282 |
|
291 |
|
283 |
info "Changes detected in $CROND_DIR" |
292 |
info "Changes detected in $CROND_DIR" |
284 |
NEED_REBUILD=1 |
293 |
NEED_REBUILD=1 |
Lines 286-316
else
Link Here
|
286 |
else |
295 |
else |
287 |
|
296 |
|
288 |
# Test each one and see if it's newer than our timestamp file |
297 |
# Test each one and see if it's newer than our timestamp file |
289 |
for i in `crond_files` ; do |
298 |
if [ -n "$(find "$CROND_DIR"/* -prune -type f ! -name '*~' -newer "$FCRONTABS_DIR"/systab.orig 2>/dev/null)" ]; then |
290 |
if [ $i -nt $FCRONTABS_DIR/systab.orig ]; then |
|
|
291 |
|
299 |
|
292 |
info "Changes detected in $CROND_DIR" |
300 |
info "Changes detected in $CROND_DIR" |
293 |
NEED_REBUILD=1 |
301 |
NEED_REBUILD=1 |
294 |
|
302 |
|
295 |
fi |
303 |
fi |
296 |
done |
|
|
297 |
|
304 |
|
298 |
fi |
305 |
fi |
299 |
|
306 |
|
300 |
fi |
307 |
fi |
301 |
|
308 |
|
302 |
# Test the standard /etc/crontab file and see if it has changed |
309 |
# Test the standard /etc/crontab and /etc/fcrontab files and see if they have changed |
303 |
if [ -f $CRONTAB_FILE -a $CRONTAB_FILE -nt $FCRONTABS_DIR/systab.orig ]; then |
310 |
REBUILD_TMPSTR="$(find "$CRONTAB_FILE" "$FCRONTAB_FILE" -prune -type f -newer "$FCRONTABS_DIR"/systab.orig -exec echo "Changes detected in {}" ';' 2>/dev/null)" |
304 |
|
311 |
if [ -n "${REBUILD_TMPSTR}" ]; then |
305 |
info "Changes detected in $CRONTAB_FILE" |
|
|
306 |
NEED_REBUILD=1 |
307 |
|
308 |
fi |
309 |
|
310 |
# Test the standard /etc/fcrontab file and see if it has changed |
311 |
if [ -f $FCRONTAB_FILE -a $FCRONTAB_FILE -nt $FCRONTABS_DIR/systab.orig ]; then |
312 |
|
312 |
|
313 |
info "Changes detected in $FCRONTAB_FILE" |
313 |
info "${REBUILD_TMPSTR}" |
314 |
NEED_REBUILD=1 |
314 |
NEED_REBUILD=1 |
315 |
|
315 |
|
316 |
fi |
316 |
fi |