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 205-217
fi
Link Here
|
205 |
# Function to scan for valid files in $CROND_DIR |
205 |
# Function to scan for valid files in $CROND_DIR |
206 |
crond_files() |
206 |
crond_files() |
207 |
{ |
207 |
{ |
208 |
[ ! -d $CROND_DIR ] && return |
208 |
[ ! -d "$CROND_DIR" ] && return |
209 |
local FILES=`echo $CROND_DIR/*` |
|
|
210 |
local FILE |
209 |
local FILE |
211 |
[ "$FILES" = "$CROND_DIR/*" ] && return |
210 |
for FILE in "$CROND_DIR"/*; do |
212 |
for FILE in $FILES; do |
211 |
if [ ! -d "$FILE" -a "$FILE" = "${FILE%\~}" ]; then |
213 |
if [ ! -d $FILE -a $FILE = "${FILE%\~}" ]; then |
212 |
echo "$FILE" |
214 |
echo $FILE |
|
|
215 |
fi |
213 |
fi |
216 |
done |
214 |
done |
217 |
} |
215 |
} |
Lines 223-259
rebuild_and_notify()
Link Here
|
223 |
logger -i -p cron.notice -t "check_system_crontabs" "Rebuilding the system fcrontab..." |
221 |
logger -i -p cron.notice -t "check_system_crontabs" "Rebuilding the system fcrontab..." |
224 |
|
222 |
|
225 |
# put a warning message at the top of the file |
223 |
# put a warning message at the top of the file |
226 |
echo -e "########################################" > $FCRONTAB_FILE_TMP |
224 |
cat <<_EOF_ > "$FCRONTAB_FILE_TMP" |
227 |
echo -e "# WARNING!!! DO NOT EDIT THIS FILE!!! #" >> $FCRONTAB_FILE_TMP |
225 |
######################################## |
228 |
echo -e "########################################" >> $FCRONTAB_FILE_TMP |
226 |
# WARNING!!! DO NOT EDIT THIS FILE!!! # |
229 |
echo -e "# Do not edit this file! It is automatically generated from" >> $FCRONTAB_FILE_TMP |
227 |
######################################## |
230 |
echo -e "# the $CRONTAB_FILE, the $FCRONTAB_FILE and $CROND_DIR/* files whenever one of" >> $FCRONTAB_FILE_TMP |
228 |
# Do not edit this file! It is automatically generated from |
231 |
echo -e "# those files is changed.\n#\n\n" >> $FCRONTAB_FILE_TMP |
229 |
# the $CRONTAB_FILE, the $FCRONTAB_FILE and $CROND_DIR/* files whenever one of |
|
|
230 |
# those files is changed. |
231 |
# |
232 |
|
233 |
_EOF_ |
232 |
|
234 |
|
233 |
# include the standard system crontab file if it exists and is not a symbolic link |
235 |
# 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 |
236 |
if [ -f "$CRONTAB_FILE" -a ! -L "$CRONTAB_FILE" ]; then |
235 |
echo -e "\n\n########################################\n# $CRONTAB_FILE\n########################################\n" >> $FCRONTAB_FILE_TMP |
237 |
cat - "$CRONTAB_FILE" <<_EOF_ >> "$FCRONTAB_FILE_TMP" |
236 |
cat $CRONTAB_FILE >> $FCRONTAB_FILE_TMP |
238 |
|
|
|
239 |
|
240 |
######################################## |
241 |
# $CRONTAB_FILE |
242 |
######################################## |
243 |
|
244 |
_EOF_ |
237 |
fi |
245 |
fi |
238 |
|
246 |
|
239 |
# print a nice filename header for each file in /etc/cron.d/ |
247 |
# print a nice filename header for each file in /etc/cron.d/ |
240 |
# and include its contents into the new fcron system crontab |
248 |
# and include its contents into the new fcron system crontab |
241 |
for i in `crond_files` ; do |
249 |
for i in `crond_files` ; do |
242 |
echo -e "\n\n########################################\n# $i\n########################################\n" >> $FCRONTAB_FILE_TMP |
250 |
cat - "$i" <<_EOF_ >> "$FCRONTAB_FILE_TMP" |
243 |
cat $i >> $FCRONTAB_FILE_TMP |
251 |
|
|
|
252 |
|
253 |
######################################## |
254 |
# $i |
255 |
######################################## |
256 |
|
257 |
_EOF_ |
244 |
done |
258 |
done |
245 |
|
259 |
|
246 |
# include the system fcrontab file if it exists and is not a symbolic link |
260 |
# include the system fcrontab file if it exists and is not a symbolic link |
247 |
if [ -f $FCRONTAB_FILE -a ! -L $FCRONTAB_FILE ]; then |
261 |
if [ -f "$FCRONTAB_FILE" -a ! -L "$FCRONTAB_FILE" ]; then |
248 |
echo -e "\n\n########################################\n# $FCRONTAB_FILE\n########################################\n" >> $FCRONTAB_FILE_TMP |
262 |
cat - "$FCRONTAB_FILE" <<_EOF_ >> "$FCRONTAB_FILE_TMP" |
249 |
cat $FCRONTAB_FILE >> $FCRONTAB_FILE_TMP |
263 |
|
|
|
264 |
|
265 |
######################################## |
266 |
# $FCRONTAB_FILE |
267 |
######################################## |
268 |
|
269 |
_EOF_ |
250 |
fi |
270 |
fi |
251 |
|
271 |
|
252 |
# Replace "@hourly" style Vixie cron extensions which fcron doesn't parse |
272 |
# 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 |
273 |
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 |
|
274 |
|
255 |
# notify fcron about the updated file |
275 |
# notify fcron about the updated file |
256 |
$FCRONTAB_PROG -c $FCRON_CONFIG_FILE $FCRONTAB_FILE_TMP -u systab |
276 |
"$FCRONTAB_PROG" -c "$FCRON_CONFIG_FILE" "$FCRONTAB_FILE_TMP" -u systab |
257 |
} |
277 |
} |
258 |
|
278 |
|
259 |
NEED_REBUILD=0 |
279 |
NEED_REBUILD=0 |
Lines 274-284
if [ -n "$FORCE" ]; then
Link Here
|
274 |
|
294 |
|
275 |
else |
295 |
else |
276 |
|
296 |
|
277 |
if [ -d $CROND_DIR ]; then |
297 |
if [ -d "$CROND_DIR" ]; then |
278 |
|
298 |
|
279 |
# This test works for file creation/deletion (deletion is not detected |
299 |
# This test works for file creation/deletion (deletion is not detected |
280 |
# by the next test) |
300 |
# by the next test) |
281 |
if [ $CROND_DIR -nt $FCRONTABS_DIR/systab.orig ]; then |
301 |
if [ "$CROND_DIR" -nt "$FCRONTABS_DIR"/systab.orig ]; then # XXX: kshism |
282 |
|
302 |
|
283 |
info "Changes detected in $CROND_DIR" |
303 |
info "Changes detected in $CROND_DIR" |
284 |
NEED_REBUILD=1 |
304 |
NEED_REBUILD=1 |
Lines 287-293
else
Link Here
|
287 |
|
307 |
|
288 |
# Test each one and see if it's newer than our timestamp file |
308 |
# Test each one and see if it's newer than our timestamp file |
289 |
for i in `crond_files` ; do |
309 |
for i in `crond_files` ; do |
290 |
if [ $i -nt $FCRONTABS_DIR/systab.orig ]; then |
310 |
if [ "$i" -nt "$FCRONTABS_DIR"/systab.orig ]; then # XXX: kshism |
291 |
|
311 |
|
292 |
info "Changes detected in $CROND_DIR" |
312 |
info "Changes detected in $CROND_DIR" |
293 |
NEED_REBUILD=1 |
313 |
NEED_REBUILD=1 |
Lines 300-306
else
Link Here
|
300 |
fi |
320 |
fi |
301 |
|
321 |
|
302 |
# Test the standard /etc/crontab file and see if it has changed |
322 |
# Test the standard /etc/crontab file and see if it has changed |
303 |
if [ -f $CRONTAB_FILE -a $CRONTAB_FILE -nt $FCRONTABS_DIR/systab.orig ]; then |
323 |
if [ -f "$CRONTAB_FILE" -a "$CRONTAB_FILE" -nt "$FCRONTABS_DIR"/systab.orig ]; then # XXX: kshism |
304 |
|
324 |
|
305 |
info "Changes detected in $CRONTAB_FILE" |
325 |
info "Changes detected in $CRONTAB_FILE" |
306 |
NEED_REBUILD=1 |
326 |
NEED_REBUILD=1 |
Lines 308-314
else
Link Here
|
308 |
fi |
328 |
fi |
309 |
|
329 |
|
310 |
# Test the standard /etc/fcrontab file and see if it has changed |
330 |
# 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 |
331 |
if [ -f "$FCRONTAB_FILE" -a "$FCRONTAB_FILE" -nt "$FCRONTABS_DIR"/systab.orig ]; then # XXX: kshism |
312 |
|
332 |
|
313 |
info "Changes detected in $FCRONTAB_FILE" |
333 |
info "Changes detected in $FCRONTAB_FILE" |
314 |
NEED_REBUILD=1 |
334 |
NEED_REBUILD=1 |